DIGG IT!
7
Comments
Published
Tuesday, December 30, 2008
at
8:35 AM
.
There is a beautiful property called mouseChildren that I had completely forgotten about. mouseChildren=false turns off all mouse events at a node in the DisplayList so that event on children only reach the actual object where mouseChildren is set to false. Essentially this allows you to enable certain graphics/objects to be invisible to the DOM Event phases and behave as part of the object they are parented to.
Ted on Twitter - @AdobeTed
Ted on Adobe Groups
Ted on LinkedIn
Ted on Facebook
Ted at Adobe
I wish I didn't forgot that one all the time..
It is an really useful property.. Not sure if I would love to have it as false by default but I really wish I could remember it often.. No that it exists on Ted's blog we might have one more reason to remember it.
therefore I use event.currentTarget
Maybe I'm wrong (and correct me if I am), but isn't there a property on the event called currentTarget that returns the component on which the listener was actually added instead of an object within this component? That would prevent from searching the component with the parent property... But the mouseChildren=false when skinning is clearly the best way to go anyway :)
event.currentTarget implies that the listener is subscribed at that point.
In my case I have 52 MovieClips (Cards with 10 Shapes avg) in all various states within Piles for a game. Instead of adding listeners directly to the Cards themselves, I implemented the game logic globally and thus there are few if any events directly subscribed to cards.
The thing is that event listeners are expensive and the more you have the more you are forcing the player to do. By moving events above the Cards I have 150 less listeners.
At the end of the day I would rather manage 6 things well than manage 150 things just to get the target right.
In this case mouseChildren=false eliminated about 520 MovieClips from emitting events, now only the parent cards react.
It is too bad that:
stage.getObjectsUnderPoint( new Point( stage.mouseX , stage.mouseY ) ) ignores mouseChildren. This method returns all surfaces below the cursor regardless of type or mouseChildren value.
Ted :)
mouseEnabled is the evil twin of mouseChildren. It enables you to turn off mouse events on individual items vs the all of mouseChildren.
Ted :)
*thinking aloud* reglib for flash
And furthermore, there is a fairly significant speed improvement:
http://natejc.com/blog/?p=83