jump to navigation

AS3 mouseChildren August 23, 2008

Posted by Mark in Actionscript 3.0.
Tags: , , , ,
trackback

This one caused me at least an hour of frustration in a recent project I was doing at work. When you have a event listener listening for the MOUSE_OVER event (lets say the object the event listener is on is a movie clip, with multiple children inside of it, like a background image, and a textfield), the yourMovieClip.mouseChildren property is automatically set to true. What that means is, every time you mouse over yourMovieClip, it will actually be like each child inside of it triggers the MOUSE_OVER event, and then if you have a MOUSE_OUT event, each time you mouse over from child to another inside of yourMovieClip, it will trigger the MOUSE_OUT event, and then the MOUSE_OVER event. This is very undesirable if you’re trying to create a rollover effect or something for your movieclip. There are two solutions:

Solution 1: Manually set the mouseChildren to false, like this:
yourMovieClip.mouseChildren = false

Solution 2: Don’t use the MOUSE_OVER event, use the ROLL_OVER event. The ROLL_OVER event will not automatically set the .mouseChildren property to true.

Follow

Get every new post delivered to your Inbox.