O'Reilly Hacks
oreilly.comO'Reilly NetworkSafari BookshelfConferences Sign In/My Account | View Cart   
Book List Learning Lab PDFs O'Reilly Gear Newsletters Press Room Jobs  



Event Handler on nested MovieClips
With this little trick you can catch events (onRollOver, onRelease,...) on nested MovieClips.

Contributed by:
Ariel Diacovetzky
[01/28/04 | Discuss (0) | Link to this hack]

Let's say you have two MovieClips, MC1 and MC2, being MC2 created inside MC1. You want both of them to catch onRollOver events. The code would be something like this:

MC1.onRollOver = function() { ...your code here.. } MC2.onRollOver = function() { ...your code here..}

This won't work, simply because MC1 event will be catched, but MC2 event won't.

To solve this problem, you have to create a third MovieClip, let's say MC3. This one will have to be created with the same shape of MC1, and attached inside MC1, in the last level. If you create it by hand, it should be created in the last layer of MC1. Once MC3 is positioned inside MC1, you have to slightly modify your code:

MC1.MC3.onRollOver = function() { ...your code here.. } MC2.onRollOver = function() { ...your code here..}

With this code, what you do is change the MovieClip that catches the event from MC1 to MC3. Since MC2 has a higher level than MC3, and higher priority on consequence, what you get is that every time the user enters on MC1, the onRollOver event of MC3 will be fired, but when MC2 is entered its event will be fired too. Ariel Diacovetzky adiacov@hotmail.com


O'Reilly Home | Privacy Policy

© 2007 O'Reilly Media, Inc.
Website: | Customer Service: | Book issues:

All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.