Disabling Mouse Events in AS3

Took me a while to figure this out. In AS2, disabling a MovieClip was done by setting the enabled property for a MovieClip to false ( the enabled property is still there
but only for MovieClip’s Over, Down, and Up frames).

Over the fence to AS3 however, to disable an object from receiving MouseEvents, you have to set it’s mouseEnabled property to false.

Things to note, if the object is a DisplayObjectContainer( i.e. a display object that can hold other display objects Sprite or MovieClip ) this WILL NOT affect it’s children ( elements nested inside ). You have to manually disable each element. This gets a little tricky because if a transparent DisplayObject with children is say on top of a button. You would have to disable both the parent DisplayObject and the child(ren) that are directly ontop of that button for the mouse to actually trigger a MouseEvent on said button. Another solution would be to just use addChild( theButton ) to move the button on top of the DisplayObject, but I think the previous solution is better ( assuming the DisplayObject on top really doesn’t need any MouseEvents ).

About this entry