User Guide

216 Chapter 8: Working with Movie Clips
In this case, the variable named nextDepth contains the value 11 because that’s the next highest
available depth for the movie clip
edit_mc.
To obtain the current highest occupied depth, subtract 1 from the value returned by
getNextHighestDepth(), as shown in the next section.
Determining the instance at a particular depth
To determine the instance at a particular depth, use
MovieClip.getInstanceAtDepth(). This
method returns a reference to the MovieClip 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 = this.getNextHighestDepth() - 1;
var instanceAtHighestDepth = this.getInstanceAtDepth(highestOccupiedDepth);
For more information, see MovieClip.getInstanceAtDepth() in Flash ActionScript Language
Reference.
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 files main Timeline and shows each
clips 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() in Flash ActionScript Language Reference.
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() in Flash ActionScript Language Reference.
Drawing shapes with ActionScript
You can use methods of the MovieClip class to draw lines and fills on the Stage. This lets you
create drawing tools for users and to draw shapes in the movie in response to events. The drawing
methods are
beginFill(), beginGradientFill(), clear(), curveTo(), endFill(),
lineTo(), lineStyle(), and moveTo().
You can use the drawing methods with any movie clip. However, if you use the drawing methods
with a movie clip that was created in authoring mode, the drawing methods execute before the
clip is drawn. In other words, content that is created in authoring mode is drawn on top of
content drawn with the drawing methods.