O'Reilly logo

ActionScript 3.0 Design Patterns by Chandima Cumaranatunge, William Sanders

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Flash's Built-in Composite Structure: the Display List

In the previous example, we extended the Sprite class to develop composite structures that display on stage. We first add the object to the composite structure, and subsequently add it to the display list using the addChild() method. What's the display list in ActionScript 3.0 applications? The display list is a tree structure with the stage as its root node. It consists of all the visible elements that'll be displayed on the stage. The display list consists of two types of objects: (1) display objects and (2) display object containers. Every element that appears on the stage is a type of display object. In contrast, display object containers not only have a visual representation on the stage, they can also have other display objects, and display object containers as children.

Close examination of the inheritance structure of the Sprite class will show two classes called DisplayObject and DisplayObjectContainer in its inheritance hierarchy.

The DisplayObject class consists of methods and properties that deal mainly with the visual presentation of an object such as the x and y properties that represent its position. The DisplayObjectContainer class inherits from DisplayObject, defines necessary properties, and implements methods to handle child objects (see the ActionScript 3.0 documentation for more detail). Some of the child handling methods implemented by the DisplayObjectContainer class are listed below.

addChild(child:DisplayObject):DisplayObject; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required