rollOver and rollOut — ignore those child mouse events!

Finally, someone has heard the frustration of all of us. We use mouseOver and mouseOut on an HBox and have to either handle all child mouseOver and Outs ourselves, or do the old mouseEnabled = false nonsense — which isn’t usually what we want anyway.

 

spriteButton.addEventListener(MouseEvent.ROLL_OVER, over);
spriteButton.addEventListener(MouseEvent.ROLL_OUT, out);

 

As found on:

http://www.kirupa.com/forum/showthread.php?p=1948052#post1948052

 

Both sets of events determine when a mouse enters or leaves the graphics area of an interactive object. The rollOver and mouseOver events fire when the mouse comes in contact with an interactive object, while rollOut and mouseOut occur when the mouse leaves the interactive object.
Where they differ is with their interaction with interactive object children. The roll events (rollOver and rollOut) simplify the process and prevent interference with child events. Essentially, this is the same as using mouseOver and mouseOut with mouseEnabled set to false. mouseOver and mouseOut with mouseEnabled provide a parent sprite with events from its children. rollOver and rollOut keeps the events on the parent object.

Leave a Reply