Updated: June 15th, 2009

The MovieClip life cycle revisited. From Event.ADDED to Event.REMOVED_FROM_STAGE.

iconJune 15th, 2009

This post is a follow up to my previous post on the MovieClip life cycle. Previously I took a look at the sequence of events that occur during the life of a single frame. This post adds to the discussion by covering event types relevant to MovieClip display object children. Those events are Event.ADDED, Event.ADDED_TO_STAGE, Event.REMOVED, and Event.REMOVED_FROM_STAGE.

What follows is the same order of events from before, plus the four new events. The four have been around since Flash Player 9, they’re just new to my discussion. And to keep things short, I’m only going to discuss the new events in depth.

  1. Event of event type Event.ENTER_FRAME dispatched
  2. Constructor code of children display objects is executed
  3. Event of event type Event.ADDED dispatched from children display objects
  4. Event of event type Event.ADDED_TO_STAGE dispatched from children display objects
  5. Event of event type Event.FRAME_CONSTRUCTED dispatched
  6. MovieClip frame actions are executed
  7. Frame actions of children MovieClips are executed
  8. Event of event type Event.EXIT_FRAME dispatched
  9. Event of event type Event.RENDER dispatched
  10. Event of event type Event.REMOVED dispatched from children display objects
  11. Event of event type Event.REMOVED_FROM_STAGE dispatched from children display objects

A special note about these events. The order of the above is only specific to MovieClips added or removed from the timeline in the Flash IDE. Manually calling addChild() or addChildAt() will dispatch Event.ADDED and Event.ADDED_TO_STAGE events immediately after the add child call. The same holds true for the removeChild() and removeChildAt() calls, and the related Event.REMOVED and Event.REMOVED_FROM_STAGE events.

Steps 3 and 4

Event.ADDED and Event.ADDED_TO_STAGE are both dispatched when the playhead moves across the MovieClip timeline and encounters a keyframe with a new child display object. If the child exists in the frame immediately previous to the keyframe there a number of conditions that will still cause both events to be dispatched. Both events will be dispatched if the child exists on a different layer, or has a different instance name, or is being masked/unmasked. Masked is defined as the mask being added by keyframe to the mask layer. Unmasked means that in the next frame the mask layer is empty.

Regardless of the order that listeners are added, Event.ADDED is dispatched before Event.ADDED_TO_STAGE. If a child, in the frame the playhead is on, is not being added neither event will be dispatched.

Steps 10 and 11

Event.REMOVED and Event.REMOVED_FROM_STAGE are dispatched at the end of the current frame when a child exists on the timeline and does not exist in the next frame. There are other conditions that cause the remove events to be dispatched from a child that remains on the timeline. Conditions mirror those of the added events and include when the child in question appears on a new keyframe on a different layer, or the child has a different instance name, or the child is about to be masked/unmasked.

Regardless of the order that listeners are added, Event.REMOVED is dispatched before Event.REMOVED_FROM_STAGE. If a child is not being removed in the next frame, then neither event will be dispatched.

7 Responses to “The MovieClip life cycle revisited. From Event.ADDED to Event.REMOVED_FROM_STAGE.”

  1. Visual of what your describing. This is from a talk given by Jim Corbett.


  2. Thanks for the link Alan. I didn’t see that talk. Good reference!

  3. This is great information. I think it would be really useful to people looking at the language reference. Would you mind adding a link to this blog here for Flash users:

  4. Good suggestion Dave. Glad you found my post helpful. I’ve added a link to this post in the CS4 AS 3.0 language reference.

  5. Dear Johannes, I really appreciate your blog!

    I’ve done a little research on this argument; the two key concepts are:
    - SWF Frame: it’s the logical unit that contains graphical code and as code
    - Flash Player Frame: it’s the time interval used by Flash runtime to update the screen and defined by frameRate property

    So the sequence you describe belongs to Flash Player Frame, I suppose.

    Ok? If so, I have a little question for you.

    Could you explain me the relationship bewteen these two concepts? In particular, how are they paired together?

    Thank you very much. Best regards.

  6. Hi Lorenzo,
    I could attempt to explain the difference between these two concepts, however Senocular recently posted a great tutorial on AS3 order of operations. The section on frame execution does a great job of explaining the differences between frames as a visual frame versus frames as a unit of time.


    In addition to that, the whole tutorial is great. Hope that helps!

  7. [...] The MovieClip life cycle revisited. From Event.ADDED to Event.REMOVED_FROM_STAGE [...]

Leave a Reply

The Author

Johannes Tacskovics
ECMAScript Developer

Portrait of Johannes Tacskovics

On front-end software engineering this is the blog of Johannes Tacskovics, a Los Angeles based ECMAScript Developer. This blog is focused on object oriented software development for the web.

Article Categories

Article Archives