Creating Movie Clips At Runtime - MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual

Actionscript reference guide
Hide thumbs Also See for FLASH MX 2004 - ACTIONSCRIPT:
Table of Contents

Advertisement

Creating movie clips at runtime

Not only can you create movie clip instances in the Flash authoring environment, but you can
also create them at runtime. ActionScript provides three ways to create new movie clips
at runtime:
By creating a new, empty movie clip instance
By duplicating an existing movie clip instance
By attaching an instance of a movie clip library symbol to the Stage
Each movie clip instance you create at runtime must have an instance name and a depth
(stacking, or z-order) value. The depth you specify determines how the new clip overlaps with
other clips on the same Timeline. (See
Creating an empty movie clip
To create an empty movie clip on the Stage, use the
MovieClip class. This method creates a movie clip as a child of the clip that calls the method. The
registration point for a newly created empty movie clip is the upper left corner.
For example, the following code creates a new child movie clip named
the movie clip named
parent_mc.createEmptyMovieClip("new_mc", 10);
The following code creates a new movie clip named
file in which the script is run, and then invokes
into itself.
_root.createEmptyMovieClip("canvas_mc", 10);
canvas_mc.loadMovie("flowers.jpg");
For more information, see
Duplicating or removing a movie clip
To duplicate or remove movie clip instances, use the
removeMovieClip()
duplicateMovieClip()
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
Duplicated movie clips are also removed if the parent movie clip is deleted.
For more information, see
on page
605.
126
Chapter 7: Working with Movie Clips
"Managing movie clip depths" on page
.
parent_mc
MovieClip.createEmptyMovieClip()
global functions, or the MovieClip class methods of the same name. The
method creates a new instance of an existing movie clip instance, assigns
duplicateMovieClip()
duplicateMovieClip()
createEmptyMovieClip()
on the root Timeline of the SWF
canvas_mc
to load an external JPEG file
loadMovie()
on page
duplicateMovieClip()
, use
on page 373
and
129.)
method of the
at a depth of 10 in
new_mc
494.
or
.
removeMovieClip()
removeMovieClip()

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004 - ACTIONSCRIPT and is the answer not in the manual?

Questions and answers

Table of Contents