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

Working with MovieClip objects<br />

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

Wh<strong>en</strong> you publish a SWF file, Flash converts all movie clip symbol instances on the Stage to MovieClip objects. You<br />

can make a movie clip symbol available to ActionScript by giving it an instance name in the Instance Name field of the<br />

Property inspector. Wh<strong>en</strong> the SWF file is created, Flash g<strong>en</strong>erates the code that creates the MovieClip instance on the<br />

Stage and declares a variable using the instance name. If you have named movie clips that are nested inside other named<br />

movie clips, those child movie clips are treated like properties of the par<strong>en</strong>t movie clip—you can access the child movie<br />

clip using dot syntax. For example, if a movie clip with the instance name childClip is nested within another clip with<br />

the instance name par<strong>en</strong>tClip, you can make the child clip’s timeline animation play by calling this code:<br />

par<strong>en</strong>tClip.childClip.play();<br />

Note: : Childr<strong>en</strong> instances placed on the Stage in the Flash authoring tool cannot be accessed by code from within the<br />

constructor of a par<strong>en</strong>t instance since they have not be<strong>en</strong> created at that point in code execution. Before accessing the<br />

child, the par<strong>en</strong>t must instead either create the child instance by code or delay access to a callback function that list<strong>en</strong>s<br />

for the child to dispatch its Ev<strong>en</strong>t.ADDED_TO_STAGE ev<strong>en</strong>t.<br />

While some legacy methods and properties of the ActionScript 2.0 MovieClip class remain the same, others have<br />

changed. All properties prefixed with an underscore have be<strong>en</strong> r<strong>en</strong>amed. For example, _width and _height<br />

properties are now accessed as width and height, while _xscale and _yscale are now accessed as scaleX and<br />

scaleY. For a complete list of the properties and methods of the MovieClip class, consult the ActionScript 3.0<br />

Refer<strong>en</strong>ce for the Adobe Flash Platform .<br />

Controlling movie clip playback<br />

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

Flash uses the metaphor of a timeline to convey animation or a change in state. Any visual elem<strong>en</strong>t that employs a<br />

timeline must be either a MovieClip object or ext<strong>en</strong>d from the MovieClip class. While ActionScript can direct any<br />

movie clip to stop, play, or go to another point on the timeline, it cannot be used to dynamically create a timeline or<br />

add cont<strong>en</strong>t at specific frames; this is only possible using the Flash authoring tool.<br />

Wh<strong>en</strong> a MovieClip is playing, it progresses along its timeline at a speed dictated by the frame rate of the SWF file.<br />

Alternatively, you can override this setting by setting the Stage.frameRate property in ActionScript.<br />

Playing movie clips and stopping playback<br />

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

The play() and stop() methods allow basic control of a movie clip across its timeline. For example, suppose you have<br />

a movie clip symbol on the Stage which contains an animation of a bicycle moving across the scre<strong>en</strong>, with its instance<br />

name set to bicycle. If the following code is attached to a keyframe on the main timeline,<br />

bicycle.stop();<br />

the bicycle will not move (its animation will not play). The bicycle’s movem<strong>en</strong>t could start through some other user<br />

interaction. For example, if you had a button named startButton, the following code on a keyframe on the main<br />

timeline would make it so that clicking the button causes the animation to play:<br />

Last updated 6/6/2012<br />

323

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

Saved successfully!

Ooh no, something went wrong!