13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Display programming<br />

Traversing the display list<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

As you’ve se<strong>en</strong>, the display list is a tree structure. At the top of the tree is the Stage, which can contain multiple display<br />

objects. Those display objects that are themselves display object containers can contain other display objects, or display<br />

object containers.<br />

Display Object<br />

Display Object<br />

Stage<br />

Instance of<br />

the main class of<br />

the SWF file<br />

Display Object<br />

Container<br />

Display Object<br />

Container<br />

Display Object<br />

Container<br />

Display Object<br />

Container<br />

Display Object<br />

The DisplayObjectContainer class includes properties and methods for traversing the display list, by means of the child<br />

lists of display object containers. For example, consider the following code, which adds two display objects, title and<br />

pict, to the container object (which is a Sprite, and the Sprite class ext<strong>en</strong>ds the DisplayObjectContainer class):<br />

var container:Sprite = new Sprite();<br />

var title:TextField = new TextField();<br />

title.text = "Hello";<br />

var pict:Loader = new Loader();<br />

var url:URLRequest = new URLRequest("banana.jpg");<br />

pict.load(url);<br />

pict.name = "banana loader";<br />

container.addChild(title);<br />

container.addChild(pict);<br />

The getChildAt() method returns the child of the display list at a specific index position:<br />

trace(container.getChildAt(0) is TextField); // true<br />

You can also access child objects by name. Each display object has a name property, and if you don’t assign it, Flash<br />

Player or AIR assigns a default value, such as "instance1". For example, the following code shows how to use the<br />

getChildByName() method to access a child display object with the name "banana loader":<br />

Last updated 6/6/2012<br />

163

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!