Adding parameters to dynamically created movie clips

When you create or duplicate a movie clip dynamically using MovieClip.attachMovie() and MovieClip.duplicateMovie(), you can populate the movie clip with parameters from another object. The initObject parameter of attachMovie() and duplicateMovie() allows dynamically created movie clips to receive clip parameters. The initObject parameter is optional.

For more information, see MovieClip.attachMovie() and MovieClip.duplicateMovieClip().

To populate a dynamically created movie clip with parameters from a specified object, do one of the following:

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 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.
  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 then assign its value to the text property of name_txt, as shown here:
    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 Properties from the Library panel's 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:
    _root.attachMovie("dynamic", "newClipName", 10, {name:"Erick"});
    
  9. Test the movie (Control > Test Movie). The name you specified in the attachMovie() call appears inside the new movie clip's text field.