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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Display programming<br />

trace(container.getChildByName("banana loader") is Loader); // true<br />

Using the getChildByName() method can result in slower performance than using the getChildAt() method.<br />

Since a display object container can contain other display object containers as child objects in its display list, you can<br />

traverse the full display list of the application as a tree. For example, in the code excerpt shown earlier, once the load<br />

operation for the pict Loader object is complete, the pict object will have one child display object, which is the<br />

bitmap, loaded. To access this bitmap display object, you can write pict.getChildAt(0). You can also write<br />

container.getChildAt(0).getChildAt(0) (since container.getChildAt(0) == pict).<br />

The following function provides an ind<strong>en</strong>ted trace() output of the display list from a display object container:<br />

function traceDisplayList(container:DisplayObjectContainer,ind<strong>en</strong>tString:String = ""):void<br />

{<br />

var child:DisplayObject;<br />

for (var i:uint=0; i < container.numChildr<strong>en</strong>; i++)<br />

{<br />

child = container.getChildAt(i);<br />

trace(ind<strong>en</strong>tString, child, child.name);<br />

if (container.getChildAt(i) is DisplayObjectContainer)<br />

{<br />

traceDisplayList(DisplayObjectContainer(child), ind<strong>en</strong>tString + "")<br />

}<br />

}<br />

}<br />

Adobe Flex<br />

If you use Flex, you should know that Flex defines many compon<strong>en</strong>t display object classes, and these classes override<br />

the display list access methods of the DisplayObjectContainer class. For example, the Container class of the mx.core<br />

package overrides the addChild() method and other methods of the DisplayObjectContainer class (which the<br />

Container class ext<strong>en</strong>ds). In the case of the addChild() method, the class overrides the method in such a way that you<br />

cannot add all types of display objects to a Container instance in Flex. The overridd<strong>en</strong> method, in this case, requires<br />

that the child object that you are adding be a type of mx.core.UICompon<strong>en</strong>t object.<br />

Setting Stage properties<br />

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

The Stage class overrides most properties and methods of the DisplayObject class. If you call one of these overridd<strong>en</strong><br />

properties or methods, Flash Player and AIR throw an exception. For example, the Stage object does not have x or y<br />

properties, since its position is fixed as the main container for the application. The x and y properties refer to the<br />

position of a display object relative to its container, and since the Stage is not contained in another display object<br />

container, these properties do not apply.<br />

Note: Some properties and methods of the Stage class are only available to display objects that are in the same security<br />

sandbox as the first SWF file loaded. For details, see “Stage security” on page 1052.<br />

Controlling the playback frame rate<br />

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

The frameRate property of the Stage class is used to set the frame rate for all SWF files loaded into the application.<br />

For more information, see the ActionScript 3.0 Refer<strong>en</strong>ce for the Adobe Flash Platform.<br />

Last updated 6/6/2012<br />

164

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

Saved successfully!

Ooh no, something went wrong!