Creating movie clips at runtime
127
Attaching a movie clip symbol to the Stage
The last way to create movie clip instances at runtime is to use
attachMovie()
. The
attachMovie()
method attaches an instance of a movie clip symbol in the SWF file’s library to
the Stage. 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 will not be exported to the
SWF file.
To assign a linkage identifier to movie clip:
1
Select Window > Library to open the Library panel.
2
Select a movie clip in the Library panel.
3
In the Library panel, select Linkage from the Library panel options menu.
The Linkage Properties dialog box appears.
4
For Linkage, select Export for ActionScript.
5
For Identifier, enter an ID for the movie clip.
By default, the identifier is the same as the symbol name.
6
You can optionally assign an ActionScript 2.0 class to the movie clip symbol. (See
“Assigning a
class to a movie clip symbol” on page 133
.)
7
If you don’t want the movie clip to load before the first frame, deselect the Export in First
Frame option.
If you deselect this option, place an instance of the movie clip on the frame of the Timeline
where you’d like it to be available. For example, if the script you’re writing doesn’t reference the
movie clip until Frame 10, then place an instance of the symbol at or before that frame in
the Timeline.
8
Click OK.
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()
.
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...