• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 7. Controlling the Movie Clip > Attaching Movie Clips

Attaching Movie Clips

The technique of duplicating existing movie clips is great, but what if you need to dynamically place a movie clip on the Stage from the Library? In this situation, you would turn to the attachMovie method. It lets you create new instances of movie clips from the Library and attach them to existing movie-clip instances already on the Stage. The attached movie clip doesn't replace the original, but actually becomes part of the movie-clip object in a parent-child relationship. If the original instance on Stage is called parentInstance, then the target path for the attached movie clip would be something like: _root.parentInstance.attachedInstance.

To attach a movie clip from the Library:

Create a movie-clip symbol, and place an instance of it from the Library onto the Stage. In the Instance panel, give it a name.

This instance will be the original, parent instance to which you'll attach another movie clip.

Create another movie-clip symbol.

From the Library options pull-down menu, choose Linkage (Figure 7.56).

Figure 7.56. The Linkage option in the Library.

The Symbol Linkage Properties dialog box appears.

From the Linkage choices, select Export this symbol, and in the Identifier field enter an identifier for your movie clip. Click OK (Figure 7.57).

Figure 7.57. The Symbol Linkage Properties dialog box.

This identifier allows you to call on this movie clip by this name from ActionScript and attach it to an instance on the Stage.

Create a button, and drag an instance of it to the Stage.

Select the button, and open the Actions panel.

Choose Actions > evaluate. In the Expression field, enter the target path of the movie-clip instance on the Stage.

Choose Objects > MovieClip > attachMovie.

The attachMovie method appears in the Expression field after the target path of the movie-clip instance (Figure 7.58).

Figure 7.58. The attachMovie method requires the arguments idName, newName, and depth.

Between the parentheses of the attachMovie method, enter the identifier of the movie clip in the Library, a name for the attached instance, and a depth level (Figure 7.59).

Figure 7.59. This attachMovie method attaches the movie clip instance called apple to the instance plate in Depth Level 2, and names the attached instance attachedApple.

Test your movie.

When you click the button that you created, the movie clip identified in the Library attaches to the instance on Stage and overlaps it. The registration point of the movie clip lines up with the registration point of the parent instance (Figure 7.60).

Figure 7.60. The movie clip instance called plate sits on the Stage (top). The actions assigned to the button attach an instance of the apple movie clip from the Library (right) to the plate instance (bottom).

There are several names you need to keep straight when you use the attachMovie method. In this example, the name of the movie clip symbol in the Library is apple movie clip. The name of the identifier is apple. The name of the attached instance is attachedApple.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint