Managing movie clip depths
129
To populate a movie clip with parameters by using
attachMovie()
:
1
In a new Flash document, create a movie clip symbol by selecting Insert > New Symbol. Type
dynamic
in the Symbol Name text box and select the Movie Clip behavior.
2
Inside the symbol, create a dynamic text field on the Stage with an instance name of
name_txt
.
3
Select the first frame of the movie clip’s Timeline and open the Actions panel (Window >
Development Panels > Actions).
4
Create a new variable called
name
, and then assign its value to the
text
property of
name_txt
,
as shown here:
var name:String;
name_txt.text = name;
5
Select Edit > Edit Document to return to the main Timeline.
6
Select the movie clip symbol in the library and select Linkage Properties from the Library panel’s
options menu.
The Linkage Properties dialog box appears.
7
Select the Export for ActionScript option, and click OK.
8
Select the first frame of the main Timeline and add the following code to the Actions panel’s
Script pane:
_root.attachMovie("dynamic", "newClipName", 10, {name:"Erick"});
9
Test the movie (Control > Test Movie). The name you specified in the
attachMovie()
call
appears inside the new movie clip’s text field.
Managing movie clip depths
Every movie clip has its own
z
-order space that determines how objects overlap within its parent
SWF file or movie clip. Every movie clip has an associated depth value, which determines if it will
render in front of or behind other movie clips in the same movie clip Timeline. When you create
a movie clip at runtime using
MovieClip.attachMovie()
,
MovieClip.duplicateMovieClip()
, or
MovieClip.createEmptyMovieClip()
, you always
specify a depth for the new clip as a method parameter. For example, the following code attaches
a new movie clip to the Timeline of a movie clip named
container_mc
with a depth value of 10.
container_mc.attachMovie("symbolID", "clip_1", 10);
This creates a new movie clip with a depth of 10 within the
z
-order space of
container_mc
.
For example, the following code attaches two new movie clips to
container_mc
. The first clip,
named
clip_1
, will render behind
clip_2
, because it was assigned a lower depth value.
container_mc.attachMovie("symbolID", "clip_1", 10);
container_mc.attachMovie("symbolID", "clip_2", 15);
Depth values for movie clips can range from -16384 to 1048575.
The MovieClip class provides several methods for managing movie clip depths: see
MovieClip.getNextHighestDepth()
on page 504
,
MovieClip.getInstanceAtDepth()
on page 503
,
MovieClip.getDepth()
on page 503
, and
MovieClip.swapDepths()
on page 535
.
Содержание FLASH MX 2004 - ACTIONSCRIPT
Страница 1: ...ActionScript Reference Guide...
Страница 8: ...8 Contents...
Страница 12: ......
Страница 24: ...24 Chapter 1 What s New in Flash MX 2004 ActionScript...
Страница 54: ...54 Chapter 2 ActionScript Basics...
Страница 80: ...80 Chapter 3 Writing and Debugging Scripts...
Страница 82: ......
Страница 110: ...110 Chapter 5 Creating Interaction with ActionScript...
Страница 112: ......
Страница 120: ...120 Chapter 6 Using the Built In Classes...
Страница 176: ......
Страница 192: ...192 Chapter 10 Working with External Data...
Страница 202: ...202 Chapter 11 Working with External Media...
Страница 204: ......
Страница 782: ...782 Chapter 12 ActionScript Dictionary...
Страница 793: ...Other keys 793 221 222 Key Key code...
Страница 794: ...794 Appendix C Keyboard Keys and Key Code Values...
Страница 798: ...798 Appendix D Writing Scripts for Earlier Versions of Flash Player...
Страница 806: ...806 Appendix E Object Oriented Programming with ActionScript 1...
Страница 816: ...816 Index...