![MACROMEDIA FLASH MX 2004 - ACTIONSCRIPT Reference Manual Download Page 126](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-actionscript/flash-mx-2004-actionscript_reference-manual_3378897126.webp)
126
Chapter 7: Working with Movie Clips
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
“Managing movie clip depths” on page 129
.)
Creating an empty movie clip
To create an empty movie clip on the Stage, use the
createEmptyMovieClip()
method of 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
new_mc
at a depth of 10 in
the movie clip named
parent_mc
.
parent_mc.createEmptyMovieClip("new_mc", 10);
The following code creates a new movie clip named
canvas_mc
on the root Timeline of the SWF
file in which the script is run, and then invokes
loadMovie()
to load an external JPEG file
into itself.
_root.createEmptyMovieClip("canvas_mc", 10);
canvas_mc.loadMovie("flowers.jpg");
For more information, see
MovieClip.createEmptyMovieClip()
on page 494
.
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()
on page 373
and
removeMovieClip()
on page 605
.
Summary of Contents for FLASH MX 2004 - ACTIONSCRIPT
Page 1: ...ActionScript Reference Guide...
Page 8: ...8 Contents...
Page 12: ......
Page 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Page 54: ...54 Chapter 2 ActionScript Basics...
Page 80: ...80 Chapter 3 Writing and Debugging Scripts...
Page 82: ......
Page 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Page 112: ......
Page 120: ...120 Chapter 6 Using the Built In Classes...
Page 176: ......
Page 192: ...192 Chapter 10 Working with External Data...
Page 202: ...202 Chapter 11 Working with External Media...
Page 204: ......
Page 782: ...782 Chapter 12 ActionScript Dictionary...
Page 793: ...Other keys 793 221 222 Key Key code...
Page 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Page 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Page 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Page 816: ...816 Index...