Essential ActionScript 3 excerpt: Display and interactivity
ActionScript 3 is a huge upgrade to the Adobe Flash programming language. The enhancements to ActionScript's performance, feature set, ease of use, cleanliness, and sophistication are considerable. Essential ActionScript 3 is a radically overhauled update to Essential ActionScript 2, focusing on the core language and object-oriented programming, as well as adding a deep look at the centerpiece of the new Flash Player API: display programming. The book covers new language features, such as the DOM-based event architecture, E4X, and namespaces—and includes real-world sample code.
The printed book is available through most major online and retail bookstores worldwide, and can be read online at Safari Books Online. For more information visit the O'Reilly store.
Essential ActionScript 3 © 2007 Colin Moock. Reproduced by permission of O'Reilly Media Inc. All rights reserved.
Display API and the display list
One of the primary activities of ActionScript programming is displaying things on the screen. Accordingly, the Flash platform provides a wide range of tools for creating and manipulating graphical content. These tools can be broken into two general categories:
Flash runtime display API: A set of classes for working with interactive visual objects, bitmaps, and vector content.
Ready-made user interface components: The Flex framework's UI component set, a sophisticated collection of customizable user-interface widgets built on top of the display API; and the Flash authoring tool's UI component set, a collection of user-interface widgets with a smaller file size, lower memory usage, and fewer features than Flex framework's UI component set.The display API is built directly into all Flash runtimes and is, therefore, available to all SWF files. The display API is designed for producing highly customized user interfaces or visual effects, such as those often found in motion graphics and games. This chapter focuses entirely on the display API.
Download the complete chapter:
Events and display hierarchies
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 to register event listeners that handle events targeted at its descendant display objects. For example, a Sprite
representing a dialog box might register a listener that handles mouse click events targeted at a nested "OK button" control. Or a Sprite representing a login form might register a listener that handles focus events targeted at nested input fields. This centralized architecture helps reduce code repetition, particularly for code that responds to user input events.
Download the complete chapter:
More Like This