Managing Movie Clip Depths - MACROMEDIA FLASH MX 2004-USING ACTIONSCRIPT IN FLASH Use Manual

Using actionscript in flash
Hide thumbs Also See for FLASH MX 2004-USING ACTIONSCRIPT IN FLASH:
Table of Contents

Advertisement

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.duplicateMovieClip()
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.attachMovie("symbolID", "clip1_mc", 10);
This example creates a new movie clip with a depth of 10 within the z-order space of
.
container_mc
The following code attaches two new movie clips to
, will render behind
clip1_mc
container_mc.attachMovie("symbolID", "clip1_mc", 10);
container_mc.attachMovie("symbolID", "clip2_mc", 15);
Depth values for movie clips can range from -16384 to 1048575. If you create or attach a new
movie clip on a depth that already has a movie clip, the new or attached clip will overwrite the
existing content.
The MovieClip class provides several methods for managing movie clip depths; for more
information, see
MovieClip.getDepth()
For more information on movie clip depths, see the following topics:
"Determining the next highest available depth" on page 215
"Determining the instance at a particular depth" on page 216
"Determining the depth of an instance" on page 216
"Swapping movie clip depths" on page 216
Determining the next highest available depth
To determine the next highest available depth within a movie clip, use
MovieClip.getNextHighestDepth()
next available depth that will render in front of all other objects in the movie clip.
The following code attaches a new movie clip, with a depth value of 10, on the root Timeline
named
file_menu
and creates a new movie clip called
this.attachMovie("menuClip","file_mc", 10, {_x:0, _y:0});
trace(file_menu.getDepth());
var nextDepth = this.getNextHighestDepth();
this.attachMovie("menuClip", "edit_mc", nextDepth, {_x:200, _y:0});
trace(edit_menu.getDepth());
MovieClip.attachMovie()
, or
clip2_mc
MovieClip.getNextHighestDepth()
, and
MovieClip.swapDepths()
. The integer value returned by this method indicates the
. It then determines the next highest available depth in that same movie clip
edit_mc
,
MovieClip.createEmptyMovieClip()
container_mc
container_mc
because it was assigned a lower depth value.
,
MovieClip.getInstanceAtDepth()
Flash ActionScript Language Reference.
at that depth.
, you always
with a depth value of 10.
. The first clip, named
Managing movie clip depths
,
215

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING ACTIONSCRIPT IN FLASH and is the answer not in the manual?

This manual is also suitable for:

Flash mx 2004 - actionscript

Table of Contents