Chapter 21. Events and Display Hierarchies
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.
Tip
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.
Hierarchical Event Dispatch
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 ...
Get Essential ActionScript 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.