130
Chapter 7: Working with Movie Clips
Determining the next highest available depth
To determine the next highest available depth within a movie clip, use
MovieClip.getNextHighestDepth()
. The integer value returned by this method indicates the
next available depth that will render in front of all other objects in the movie clip.
The following code creates a new movie clip, with a depth value of 10, on the Timeline of the
movie clip named
menus_mc
. It then determines the next highest available depth in that same
movie clip, and creates a new movie clip at that depth.
menus_mc.attachMovie("menuClip","file_menu", 10);
var nextDepth = menus_mc.getNextHighestDepth();
menus_mc.attachMovie("menuClip", "edit_menu", nextDepth);
In this case, the variable named
nextDepth
contains the value 11, because that’s the next highest
available depth for the movie clip
menus_mc
.
To obtain the current highest occupied depth, subtract 1 from the value returned by
getNextHighestDepth()
, as shown in the next section (see
“Determining the instance at a
particular depth” on page 130
).
Determining the instance at a particular depth
To determine the instance at particular depth, use
MovieClip.getInstanceAtDepth()
. This
method returns a reference to the instance at the specified depth.
The following code combines
getNextHighestDepth()
and
getInstanceAtDepth()
to
determine the movie clip at the (current) highest occupied depth on the root Timeline.
var highestOccupiedDepth = _root.getNextHighestDepth() - 1;
var instanceAtHighestDepth = _root.getInstanceAtDepth(highestOccupiedDepth);
For more information, see
MovieClip.getInstanceAtDepth()
on page 503
.
Determining the depth of an instance
To determine the depth of a movie clip instance, use
MovieClip.getDepth()
.
The following code iterates over all the movie clips on a SWF file’s main Timeline and displays
each clip’s instance name and depth value in the Output panel.
for(each in _root) {
var obj = _root[each];
if(obj instanceof MovieClip) {
var objDepth = obj.getDepth();
trace(obj._name + ":" + objDepth)
}
}
For more information, see
MovieClip.getDepth()
on page 503
.
Swapping movie clip depths
To swap the depths of two movie clips on the same Timeline, use
MovieClip.swapDepths()
. For
more information, see
MovieClip.swapDepths()
on page 535
.
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...