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

Working with movie clips<br />

The Sc<strong>en</strong>e class has several properties that give information about a sc<strong>en</strong>e. The labels property returns an array of<br />

FrameLabel objects repres<strong>en</strong>ting the frame labels in that sc<strong>en</strong>e. The name property returns the sc<strong>en</strong>e’s name as a string.<br />

The numFrames property returns an int repres<strong>en</strong>ting the total number of frames in the sc<strong>en</strong>e.<br />

Creating MovieClip objects with ActionScript<br />

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

One way of adding cont<strong>en</strong>t to the scre<strong>en</strong> in Flash is by dragging assets from the library onto the Stage, but that is not<br />

the only workflow. For complex projects, experi<strong>en</strong>ced developers commonly prefer to create movie clips<br />

programatically. This approach brings several advantages: easier re-use of code, faster compile-time speed, and more<br />

sophisticated modifications that are available only to ActionScript.<br />

The display list API of ActionScript 3.0 streamlines the process of dynamically creating MovieClip objects. The ability<br />

to instantiate a MovieClip instance directly, separate from the process of adding it to the display list, provides flexibility<br />

and simplicity without sacrificing control.<br />

In ActionScript 3.0, wh<strong>en</strong> you create a movie clip (or any other display object) instance programatically, it is not visible<br />

on the scre<strong>en</strong> until it is added to the display list by calling the addChild() or the addChildAt() method on a display<br />

object container. This allows you to create a movie clip, set its properties, and ev<strong>en</strong> call methods before it is r<strong>en</strong>dered<br />

to the scre<strong>en</strong>. For more information on working with the display list, see “Working with display object containers” on<br />

page 159.<br />

Exporting library symbols for ActionScript<br />

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

By default, instances of movie clip symbols in a Flash docum<strong>en</strong>t’s library cannot be dynamically created (that is,<br />

created using only ActionScript). This is because each symbol that is exported for use in ActionScript adds to the size<br />

of your SWF file, and it’s recognized that some symbols might not be int<strong>en</strong>ded for use on the stage. For this reason, in<br />

order to make a symbol available in ActionScript, you must specify that the symbol should be exported for<br />

ActionScript.<br />

To export a symbol for ActionScript:<br />

1 Select the symbol in the Library panel and op<strong>en</strong> its Symbol Properties dialog box.<br />

2 If necessary, activate the Advanced settings.<br />

3 In the Linkage section, activate the Export for ActionScript checkbox.<br />

This will activate the Class and Base Class fields.<br />

By default, the Class field is populated with the symbol name, with spaces removed (for example, a symbol named<br />

“Tree House” would become “TreeHouse”). To specify that the symbol should use a custom class for its behavior,<br />

<strong>en</strong>ter the full name of the class including its package in this field. If you want to be able to create instances of the<br />

symbol in ActionScript, but don’t need to add any additional behavior, you can leave the class name as-is.<br />

The Base Class field’s value defaults to flash.display.MovieClip. If you want your symbol to ext<strong>en</strong>d the<br />

functionality of another customer class, you can specify that class’s name instead, as long as that class ext<strong>en</strong>ds the<br />

Sprite (or MovieClip) class.<br />

4 Press the OK button to save the changes.<br />

Last updated 6/6/2012<br />

326

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

Saved successfully!

Ooh no, something went wrong!