The switch from Actionscript 2.0 to Actionscript 3.0 saw many changes, as we all know. Some were superficial or minor, like removing underscores from certain properties. So _alpha became alpha. The range of alpha became 0 to 1 (formerly 0 to 100). These are among the small changes. Other changes were more extensive; some much more. Of all the changes, the two biggest ones were undoubtedly the display list and the event model. In fact, if you can master these two aspects of Actionscript 3.0, the remainder should be relatively easy.
Of those two, the display list is the easiest to learn. So that leaves the event model. The new event model relies on a system of event dispatchers and event listeners. The event dispatchers are the various objects in your flash movie. If you create things that can be displayed on the screen, you are creating event dispatchers, because in Actionscript 3.0 all display objects ultimately descend from the EventDispatcher class. So our old familiar friend from Actionscript 2.0, the MovieClip, is now an event dispatcher in Actionscript 3.0! So are all of the other display objects. And many objects that aren't display objects are event dispatchers, too, but those won't be the focus of this article. What we are concerned with here is what is known as the event flow. When a display list is involved, and an event is dispatched by an object on the display list, that event is sent through the display list from object to object, looking for event listeners that have been defined along the way. In this article, you are going to see just how useful that feature can be!
A listener is a function that you write to handle events that are being dispatched. A listener is registered with an event dispatcher using the event dispatcher's addEventListener() method. Even if you are quite new to Actionscript 3.0, you probably have already written some event listener functions and added them to MovieClip instances, because you have to if you want to get any kind of interactivity at all. Maybe you've heard of the event flow, and the associated terminology, and wondered what it was all about, especially in terms of how to make it work for you in your projects, but you were put off because it sounded way too complicated. So you just continue on, adding an event listener to each and every object for each and every kind of event you want to listen for, racking up a huge stack of event listeners, while at the same time having this nagging thought that there must be a better way, something powerful that you're not tapping into and taking advantage of.
That something is the event flow, naturally. Trouble is, it can be very intimidating and confusing at first, as you may have already found out (in the end though, it's not all that bad--and that's the good news)! So, if you've read books, seen diagrams (or consulted the docs--yecch!) and still don't understand exactly how it works, let alone what it can do for you, don't worry. I'm betting that you're not alone--and that's why I wrote this article.
Hi, Jody Hall
I am new member. This article the most impressive and most explanatory i ever came across to explaing event flow.
I am new to actionscript and my question which I have been reading many sites about actionscript but no answer.
My question is I have a mc1 on the stage and I put anower nested mc2 inside it and also inside mc2 there is another nested mc3
all of them they have time line animation . How can I instuct move mc2 and mc3 to go to a certain frame and stop or play?
I hope to get clear answer
Hey Fareed,
Thanks for the nice comments!
In Actionscript 3.0, now that there is the concept of a display list, there is no longer much of a need for nesting movie clips. You can still do it, but now there is way less of a need. Instead, you can just put one mc on the display list of another mc. Now the mc's will be related in a parent/child way, but they are not at all nested. Let's say you add mc2 to the display list of mc1 using addChild(). mc2 is now a child of mc1, but is not nested inside of it. The path to mc2 is NOT mc1.mc2. Rather, you can still address mc2 directly, as in: mc2.gotoAndPlay("whatever");
If you do choose to nest movie clips, I believe there are issues addressing mc's that aren't present on the first frame of their parent.
I really loved this tutorial because it was in-depth. I was working on something little (AS3) and I was
having problems moving from 1 frame to another based on a button click. I think I should get it working now
Thank you very much.
This tutorial is great. I went from no understanding of Event Flow to complete understanding of Event Flow in 45 minutes.