开发者

Multiple mouse move detection

开发者 https://www.devze.com 2023-02-19 14:53 出处:网络
Multiple mouse move detection I want to make an interaction with the mouse pointer like this: http://www.youtube.com/vision2watch#p/u/38/LlHGYaP9fgM

Multiple mouse move detection

I want to make an interaction with the mouse pointer like this: http://www.youtube.com/vision2watch#p/u/38/LlHGYaP9fgM

So basically there are 2 classes; one is the Main class and another is the image_child class. Main class is responsible for the main interaction like loading XML loader class, set texts and other things. image_child class is resp开发者_JAVA百科onsible for rendering and presenting the images on the stage with their movements and interaction when the mouse is moving. I have a problem.

There are 2 methods to render this interaction on the stage:

Method A:

1- Make an array of image_child objects called ImageBank Array = new Array().

2- Each child has a “.cordinator(x,y)” function which I can call and send mouse x and y to the class. .i.e ImageBank[i].cordinator(120,144);

3- Put Array in a loop like “For” or “While” in Main class, give mouse x and y and render the interaction to stage; and redo the loop each time I have a mouse move with new coordination.

/// 120 is mouse x and 144 is mouse y

for (var i:int = 0; i< ImageBank.length; i++) {

    ImageBank[i].cordinator(120,144);

}

Method B:

1- Write a mouse-move event listener inside each image_child object which detects mouse movements.

2- Get mouse x and y from that event.

3- Render the interaction to stage.(inside each image_child instance)

It seems that method B is easier and clean but in method B each instance has a mouse-move event listener and if I have 70 instances then I have 70 mouse-move event listeners which I think is not a good thing at all.

Do you have any ideas or any suggestions? ( I`m looking for best performance and smooth movement.)


I think the easiest solution would be pass your event into your image_child class, from the Main class mouse move.

So, in your Main class, you could have your listener do something like this:

private function listenerName(evt:MouseEvent):void    
{
    for(var i=0; i<imgChildContainer.numChildren-1; i++)
    {
        var mc:MovieClip = imgChildContainer.getChildAt(i);
        mc.mouseMove(Yourcoordinateshere/Whatever);
    }
}

This assumes your image_childs are in a container.

Other than that, I would put the listeners on the image_child, which you mentioned you didn't want to do.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消