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.

  1. In the Timeline, select Frame 1 of the Actions layer.
  2. In 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.

  3. With 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.