Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Movie Clips > Creating movie clips at runtime > Attaching a movie clip symbol to the Stage | |||
The last way to create movie clip instances at runtime is to use the attachMovie() method. The attachMovie() method attaches to the Stage an instance of a movie clip symbol in the SWF file's library. The new clip becomes a child clip of the clip that attached it.
To use ActionScript to attach a movie clip symbol from the library, you must export the symbol for ActionScript and assign it a unique linkage identifier. To do this, you use the Linkage Properties dialog box.
By default, all movie clips that are exported for use with ActionScript load 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 also specify whether this content should be added before the first frame. If it isn't added in the first frame, you must include an instance of it in some other frame of the SWF file; if you don't, the element is not exported to the SWF file.
To assign a linkage identifier to a movie clip:The Linkage Properties dialog box appears.
By default, the identifier is the same as the symbol name.
You can optionally assign an ActionScript class to the movie clip symbol. This lets the movie clip inherit the methods and properties of a specified class. (See Assigning a class to a movie clip symbol.)
If you deselect this option, place an instance of the movie clip on the frame of the timeline where you want it to be available. For example, if the script you're writing doesn't reference the movie clip until Frame 10, place an instance of the symbol at or before Frame 10 on the Timeline.
After you've assigned a linkage identifier to a movie clip, you can attach an instance of the symbol to the Stage at runtime by using attachMovie().
To attach a movie clip to another movie clip:For example, to attach the movie clip to the root timeline, type this.
attachMovie(). idName, specify the identifier you entered in the Linkage Properties dialog box.newName, enter an instance name for the attached clip so that you can target it. depth, enter the level at which the duplicate movie clip will be attached to the movie clip. Each attached movie clip has its own stacking order, with level 0 as the level of the originating movie clip. Attached movie clips are always on top of the original movie clip, as shown in the following example:
this.attachMovie("calif_id", "california_mc", 10);
For more information, see attachMovie (MovieClip.attachMovie method) in the ActionScript 2.0 Language Reference.
|
|
|
|