is supported in part by

April 13, 2007

Chapter 20, Paragraphs 1-5 & 10-17, Essential ActionScript 3.0

Here are 12 paragraphs from Chapter 20 of Essential ActionScript 3.0.

20. The 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:

* The 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
   * 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.

The Flex framework’s UI component set is part of the Flex framework, an external class library included with Adobe Flex Builder, and also available in standalone form for free at: The Flex framework’s UI component set is designed for building applications with relatively standard user interface controls (scrollbars, pull-down menus, data grids, etc.). The Flex framework’s interface widgets are typically used in MXML applications, but can also be included in primarily ActionScript-based applications. For details on using the Flex framework in ActionScript, see Chapter 30.

The Flash authoring tool’s UI component set is designed for use with .swf files created in the Flash authoring tool, and for situations where file size and low memory usage are more important than advanced component features such as data binding and advanced styling options. The Flash authoring tool’s UI component set and the Flex framework’s UI component set share a very similar API, allowing developers to reuse knowledge when moving between the two component sets.


DisplayObject, the root of the core-display-class hierarchy, defines the display API’s first tier of graphical functionality: on-screen display. All classes that inherit from DisplayObject gain a common set of fundamental graphical characteristics and capabilities. For example, every descendant of DisplayObject can be positioned, sized, and rotated with the variables x, y, width, height, and rotation. More than just a simple base class, DisplayObject is the source of many sophisticated capabilities in the display API, including (but not limited to):

* Converting coordinates (see the DisplayObject class’s instance methods localToGlobal() and globalToLocal() in Adobe’s ActionScript Language Reference)
* Checking intersections between objects and points (see the DisplayObject class’s instance methods hitTestObject() and hitTestPoint() in Adobe’s ActionScript Language Reference)
* Applying filters, transforms, and masks (see the DisplayObject class’s instance variables filters, transform, and mask in Adobe’s ActionScript Language Reference)
* Scaling disproportionately for “stretchy” graphical layouts (see the DisplayObject class’s instance variable scale9grid in Adobe’s ActionScript Language Reference)

Note that this book occasionally uses the informal term “display object” to mean “any instance of a class descending from the DisplayObject class.”

DisplayObject’s direct concrete subclasses—Video, Bitmap, Shape, MorphShape, and StaticText—represent the simplest type of displayable content: basic on-screen graphics that cannot receive input or contain nested visual content. The Video class represents streaming video. The Bitmap class renders bitmap graphics created and manipulated with the supporting BitmapData class. The Shape class provides a simple, lightweight canvas for vector drawing. And the special MorphShape and StaticText classes represent, respectively, shape tweens and static text created in the Flash authoring-tool. Neither MorphShape nor StaticText can be instantiated with ActionScript.

DisplayObject’s only abstract subclass, InteractiveObject, establishes the second tier of functionality in the display API: interactivity. All classes that inherit from InteractiveObject gain the ability to respond to input events from the user’s mouse and keyboard. InteractiveObject’s direct concrete subclasses—TextField, SimpleButton—represent two distinct kinds of interactive graphical content. The TextField class represents a rectangular area for displaying formatted text and receiving text-based user input. The SimpleButton class represents Button symbols created in the Flash authoring-tool, and can also be used to quickly create interactive buttons via ActionScript code. By responding to the input events broadcast by the TextField or SimpleButton the programmer can add interactivity to an application. For example, a TextField instance might be programmed to change background color in response to a FocusEvent.FOCUS_IN event and a SimpleButton instance might be programmed to submit a form in response to a MouseEvent.CLICK event.

InteractiveObject’s only abstract subclass, DisplayObjectContainer, is the base of the third, and final functional tier in the display API: containment. All classes that inherit from DisplayObjectContainer gain the ability to physically contain any other DisplayObject instance. Containers are used to group multiple visual objects so they can be manipulated as one. Any time a container is moved, rotated, or transformed, the objects it contains inherit that movement, rotation, or transformation. Likewise, any time a container is removed from the screen, the objects it contains are removed with it. Furthermore, containers can be nested within other containers to create hierarchical groups of display objects. When referring to the objects in a display hierarchy, this book use standard tree-structure terminology; for example, an object that contains another object in a display hierarchy is referred to as that object’s parent, while the contained object is referred to as the parent’s child. In a multilevel display hierarchy, the objects above a given object in the hierarchy are referred to as the object’s ancestors. Conversely, the objects below a given object in the hierarchy are referred to as the object’s descendants. Finally, the top-level object in the hierarchy (the object from which all other objects descend) is referred to as the root object.

Don’t confuse the ancestor objects and descendant objects in a display hierarchy with the ancestor classes and descendant classes in an inheritance hierarchy. For clarity, this book occasionally uses the terms “display ancestors” and “display descendants” when referring to ancestor objects and descendant objects in a display hierarchy.

DisplayObjectContainer’s subclasses—Sprite, MovieClip, Stage, and Loader—each provide a unique type of empty containment structure, waiting to be filled with content. Sprite is the centerpiece of the container classes. As a descendant of both the InteractiveObject the DisplayObjectContainer classes, Sprite provides the perfect foundation for building custom user interface elements from scratch. The MovieClip class is an enhanced type of Sprite that represents animated content created in the Flash authoring tool. The Stage class represents the Flash runtime’s main display area (the viewable region within the borders of the application window). And finally, the Loader class is used to load external graphical content locally or over the Internet.

Posted by moock at April 13, 2007 10:11 PM