O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Display-Hierarchy Mutation and the Event Flow

Immediately before ActionScript dispatches a given event, it predetermines the entire event flow for that dispatch based on the current state of the event target's display hierarchy. That is, the list of objects that will be notified of the event, and the order in which those objects will be notified, is predetermined before the event dispatch begins. Once the event dispatch begins, objects are notified of the event according to that predetermined order—even if the structure of the target object's display hierarchy is modified by event listeners during the event dispatch.

For example, suppose we have a TextField instance contained by a Sprite instance that is, itself, contained by the Stage instance. Further suppose we register a listener, stageClickListener( ), with the Stage instance for capture-phase MouseEvent.CLICK event notification, as shown in the following code:

stage.addEventListener(MouseEvent.CLICK, stageClickListener, true);

Finally, suppose that the registered stageClickListener( ) function contains code that removes the TextField object from its Sprite object parent, as follows:

private function stageClickListener (e:MouseEvent):void {
  // If the TextField object was clicked...
  if (e.target == textField) {
    // ...remove it
    removeChild(textField);
    textField = null;
  }
}

When the user clicks the text field, ActionScript dispatches a MouseEvent.CLICK event targeted at the TextField object. Before the dispatch begins, ActionScript ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required