User Guide

The event flow 351
If a user clicks on Child1 Node, Flash Player dispatches an event object into the event flow.
As the following image shows, the objects journey starts at
Stage, moves down to Parent
Node
, then moves to Child1 Node, and then “bubbles” back up to Stage, moving through
Parent Node again on its journey back to Stage.
In this example, the capture phase comprises
Stage and Parent Node during the initial
downward journey. The target phase comprises the time spent at
Child1 Node. The bubbling
phase comprises
Parent Node and Stage as they are encountered during the upward journey
back to the root node.
The event flow contributes to a more powerful event handling system than that previously
available to ActionScript programmers. In previous versions of ActionScript, the event flow
does not exist, which means that event listeners can be added only to the object that generates
the event. In ActionScript 3.0, you can add event listeners not only to a target node, but also
to any node along the event flow.
The ability to add event listeners along the event flow is useful when a user interface
component comprises more than one object. For example, a button object often contains a
text object that serves as the buttons label. Without the ability to add a listener to the event
flow, you would have to add a listener to both the button object and the text object to ensure
that you receive notification about click events that occur anywhere on the button. The
existence of the event flow, however, allows you to place a single event listener on the button
object that handles click events that occur either on the text object or on the areas of the
button object that are not obscured by the text object.
Not every event object, however, participates in all three phases of the event flow. Some types
of events, such as the
enterFrame and init event types, are dispatched directly to the target
node and participate in neither the capture phase nor the bubbling phase. Other events may
target objects that are not on the display list, such as events dispatched to an instance of the
Socket class. These event objects will also flow directly to the target object, without
participating in the capture and bubbling phases.
Stage
Parent Node
Child1 Node
Child2 Node
Capture
Phase
Bubbling
Phase
Target Phase