ActionScript 3.0: Event Propagation

I learnt AS3 in a hurry – I had a couple of weeks to get my head around it and get things working – no nicities – just get it working so you can teach it… And what I missed by scrabbling through the ActionScript 3.0 Bible was the propagating nature of the event model. And it’s awesome! You layer things on other things and the event propagates down the tree until it hits the last branch..

In the example below I just create three boxes bound to a Box class, and when adding them to the screen I don’t add them all to the stage – I just add the first one to the stage, add the second one to the first one, and add the last one to the middle one, and just look at MOUSE_OVER and MOUSE_OUT events. Because they’re MovieClips added to MovieClips etc, the event travels down the tree and hits each branch using the current status to work on. Move your mouse over the boxes below to see what I mean:

That’s going to come in really useful… I can just feel it.

Source Code:

Box class:

2 thoughts on “ActionScript 3.0: Event Propagation”

  1. I think is very usefull, and you will probably hit me for asking this, but: How do I prevent event propagation?

    I have a parent MC with a ‘MouseOver’ event listener, and I don’t want that on the children MC.

    Thanks.

Leave a Reply

Your email address will not be published.