P. 1
Learning Flash

Learning Flash

|Views: 12|Likes:
Published by gombestralala

More info:

Published by: gombestralala on Feb 01, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

10/23/2011

pdf

text

original

You can configure your document to play a movie clip at runtime. Using the attachMovie()
method, you can attach an instance of a movie clip in the Library panel to the Stage even though
you have not placed an instance on the Stage.

With the attachMovie() method, you must export the symbol for ActionScript and assign it a
unique linkage identifier, which is different from the instance name.

1In the Library panel, right-click the MCTrio symbol and select Linkage from the context menu.

2In the Linkage Properties dialog box, select Export for ActionScript.

3In the Identifier text box, verify that MCTrio appears as the linkage name.

4Verify that Export in First Frame is selected, and then click OK.
Movie clips that are exported for use with ActionScript load, by default, before the first frame
of the SWF file that contains them. This can create a delay before the first frame plays. When
you assign a linkage identifier to an element, you can specify that the movie clip load on the
first frame to avoid playback delays.

Play a movie clip

103

Use the attachMovie() method to play a movie clip

You’ll now use the attachMovie() method to load the movie clip and provide the symbol with
an instance name. Since the instance of the symbol does not exist on the Stage, you’ll create the
instance name programmatically.

1In the Timeline, select Frame 1 of the Actions layer.

2In the Script pane of the Actions panel, place the insertion point at the end of your last line of
code. Press Enter or Return, and then type the following to add a comment and create a
new function:

//function plays trio_mc when attachMovie_btn instance is released.
attachMovie_btn.onRelease = function(){

Next, you’ll specify what the function does: it plays the movie clip on the root Timeline, which
is the main Timeline. In your script, you’ll refer to the movie clip by the linkage identifier
name in the Linkage Properties dialog box (MCTrio).
Additionally, even though you didn’t place an instance of the MCTrio symbol on the Stage,
you’ll use ActionScript to create an instance name for the symbol. The instance name that
you’ll specify is trio_mc.
3With the insertion point at the end of the last line of script, press Enter or Return. Then type
the following:

_root.attachMovie("MCTrio", "trio_mc", 1);

The number 1 in the script that you just typed refers to the depth on the layer in which to play
the movie clip.
Every movie clip instance has its own z axis (depth) that determines the stacking order of a
movie clip within its parent SWF file or movie clip. When you create a new movie clip at
runtime using the attachMovie() method, you always specify a depth for the new clip as a
method parameter.
For more information about the attachMovie() method, see attachMovie() in ActionScript
Dictionary Help.

Specify movie clip Stage coordinates

In addition to the z axis for the movie clip, you must specify the x and y coordinates to place the
movie clip within the Stage area at runtime.
•Press Enter or Return after the last line in the Script pane and type the following:

trio_mc._x = 275;
trio_mc._y = 200;
};

104

Chapter 13: Add Interactivity with ActionScript

Unload the movie clip

After the movie clip plays, you need a way to remove the movie clip from the Stage when the user
goes to Scene 2. You can modify your script for the goScene_btn to “unload” the movie clip.

1In the Timeline, select Frame 1 of the Actions layer. Then click at the end of the following line
of script in the Script pane, within the function that takes the user to Scene 2, to place the
insertion point:

gotoAndStop("Scene 2", 1);

2Press Enter or Return and type the following script, which unloads the movie clip when the
function runs, so that the movie clip does not continue to play when the user goes to Scene 2:

unloadMovie("trio_mc");

Your entire function for the goScene_btn should appear as follows:

//This script takes user to Scene 2 when goScene_btn instance is released
goScene_btn.onRelease = function() {
gotoAndStop("Scene 2", 1);
unloadMovie("trio_mc");

};

Your entire script should appears as follows:

//stops the playhead at Frame 1
stop();

//This script takes user to Scene 2 when goScene_btn instance is released
goScene_btn.onRelease = function (){
gotoAndStop("Scene 2", 1);
unloadMovie("trio_mc");

};

//This function plays trio_mc when attachMovie_btn instance is released.
attachMovie_btn.onRelease = function(){
_root.attachMovie("MCTrio", "trio_mc", 1);
trio_mc._x = 275;
trio_mc._y = 200;

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->