362 Working with Movie Clips
Duplicating or removing a movie clip
To duplicate or remove movie clip instances, use the duplicateMovieClip() or
removeMovieClip() global functions, or the MovieClip class methods of the same name.
The
duplicateMovieClip() method creates a new instance of an existing movie clip
instance, assigns it a new instance name, and gives it a depth, or z-order. A duplicated movie
clip always starts at Frame 1, even if the original movie clip was on another frame when
duplicated and is always in front of all previously defined movie clips placed on the timeline.
To delete a movie clip you created with
duplicateMovieClip(), use removeMovieClip().
Duplicated movie clips are also removed if the parent movie clip is deleted.
For more information, see
duplicateMovieClip function and removeMovieClip
function
in the ActionScript 2.0 Language Reference.
For an example source file that creates and removes numerous movie clips at runtime, you can
find a sample source file, animation.fla, in the Samples folder on your hard disk
■ In Windows, browse to boot drive\Program Files\Macromedia\Flash 8\Samples and
Tutorials\Samples\ActionScript\Animation.
■ On the Macintosh, browse to Macintosh HD/Applications/Macromedia Flash 8/Samples
and Tutorials/Samples/ActionScript/Animation.
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:
1. Select Window > Library to open the Library panel.
2. Select a movie clip in the Library panel.