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 />

In ActionScript 3.0, you can easily traverse the display list sequ<strong>en</strong>tially; there are no gaps in the index numbers of a<br />

child list of a display object container. Traversing the display list and managing the depth of objects is much easier than<br />

was possible in ActionScript 1.0 and 2.0. In ActionScript 1.0 and 2.0, a movie clip could contain objects with<br />

intermitt<strong>en</strong>t gaps in the depth order, which could make it difficult to traverse the list of object. In ActionScript 3.0,<br />

each child list of a display object container is cached internally as an array, resulting in very fast lookups (by index).<br />

Looping through all childr<strong>en</strong> of a display object container is also very fast.<br />

In ActionScript 3.0, you can also access childr<strong>en</strong> in a display object container by using the getChildByName() method<br />

of the DisplayObjectContainer class.<br />

Full traversal of the display list<br />

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

In ActionScript 1.0 and 2.0, you could not access some objects, such as vector shapes, that were drawn in the Flash<br />

authoring tool. In ActionScript 3.0, you can access all objects on the display list—both those created using ActionScript<br />

and all display objects created in the Flash authoring tool. For details, see “Traversing the display list” on page 163.<br />

Off-list display objects<br />

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

In ActionScript 3.0, you can create display objects that are not on the visible display list. These are known as off-list<br />

display objects. A display object is added to the visible display list only wh<strong>en</strong> you call the addChild() or<br />

addChildAt() method of a DisplayObjectContainer instance that has already be<strong>en</strong> added to the display list.<br />

You can use off-list display objects to assemble complex display objects, such as those that have multiple display object<br />

containers containing multiple display objects. By keeping display objects off-list, you can assemble complicated<br />

objects without using the processing time to r<strong>en</strong>der these display objects. You can th<strong>en</strong> add an off-list display object<br />

to the display list wh<strong>en</strong> it is needed. Also, you can move a child of a display object container on and off the display list<br />

and to any desired position in the display list at will.<br />

Easier subclassing of display objects<br />

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

In ActionScript 1.0 and 2.0, you would oft<strong>en</strong> have to add new MovieClip objects to a SWF file to create basic shapes<br />

or to display bitmaps. In ActionScript 3.0, the DisplayObject class includes many built-in subclasses, including Shape<br />

and Bitmap. Because the classes in ActionScript 3.0 are more specialized for specific types of objects, it is easier to<br />

create basic subclasses of the built-in classes.<br />

For example, in order to draw a circle in ActionScript 2.0, you could create a CustomCircle class that ext<strong>en</strong>ds the<br />

MovieClip class wh<strong>en</strong> an object of the custom class is instantiated. However, that class would also include a number<br />

of properties and methods from the MovieClip class (such as totalFrames) that do not apply to the class. In<br />

ActionScript 3.0, however, you can create a CustomCircle class that ext<strong>en</strong>ds the Shape object, and as such does not<br />

include the unrelated properties and methods that are contained in the MovieClip class. The following code shows an<br />

example of a CustomCircle class:<br />

Last updated 6/6/2012<br />

157

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

Saved successfully!

Ooh no, something went wrong!