In Chapter 12, we studied ActionScript's built-in event architecture in general terms. In this chapter, we'll take a closer look at how that event architecture specifically caters to objects in display hierarchies.
ActionScript's system of dispatching events through an object hierarchy, as described in this chapter, is based on the W3C Document Object Model (DOM) Level 3 Events Specification, available at http://www.w3.org/TR/DOM-Level-3-Events.
As we saw in Chapter 12, when
ActionScript dispatches an event targeted at an object that is not
part of a display hierarchy, that target is the sole object notified
of the event. For example, when a Sound object's sound finishes playing,
ActionScript dispatches an
Event.COMPLETE event targeted at the
associated SoundChannel object.
The SoundChannel object is not
part of a display hierarchy, so it is the sole object notified that
the event occurred.
By contrast, when ActionScript dispatches an event targeted at an object that is part of a display hierarchy, that target and all of its display hierarchy ancestors are notified that the event occurred. For example, if a Sprite object contains a TextField object, and the user clicks the TextField object, both the TextField object (the event target) and the Sprite object (the event target's ancestor) are notified that the mouse click occurred.
ActionScript's hierarchical event dispatch system enables every display object container ...