User Guide

214 Chapter 8: Working with Movie Clips
To populate a dynamically created movie clip with parameters from a specified object:
Do one of the following:
Use the following syntax with attachMovie():
myMovieClip.attachMovie(idName, newName, depth [, initObject])
Use the following syntax with duplicateMovie():
myMovieClip.duplicateMovie(idName, newName, depth [, initObject])
The initObject parameter specifies the name of the object whose parameters you want to use to
populate the dynamically created movie clip.
To populate a movie clip with parameters by using attachMovie():
1.
In a new Flash document, create a movie clip symbol by selecting Insert > New Symbol. Type
dynamic_mc in the Symbol Name text box, and select the Movie Clip behavior.
2.
Inside the symbol, create a dynamic text field on the Stage with an instance name of name_txt.
Make sure this text field is below and to the right of the registration point.
3.
Select the first frame of the movie clip’s Timeline, and open the Actions panel (Window >
Development Panels > Actions).
4.
Create a new variable called name, and assign its value to the text property of name_txt, as
shown in the following example:
var name:String;
name_txt.text = name;
5.
Select Edit > Edit Document to return to the main Timeline.
6.
Select the movie clip symbol in the library, and select Linkage from the Library options menu.
The Linkage Properties dialog box appears.
7.
Select the Export for ActionScript option, and click OK.
8.
Select the first frame of the main Timeline, and add the following code to the Actions panel’s
Script pane:
/* Attaches a new clip called Erick and
moves it to an x and y coordinate of 50 */
this.attachMovie("dynamic_mc", "newClip_mc", 99, {name:"Erick", _x:50,
_y:50});
9.
Test the movie (Control > Test Movie). The name you specified in the attachMovie() call
appears inside the new movie clip’s text field.