13.4.2.3. Assigning depths to instances in the programmatically generated clip stack
You
may be wondering what determines the
stacking order of clips C, D,
and E, or of clips A and
F in Figure 13-3. The stacking
order of a programmatically generated clip is determined by the
depth argument passed to the
attachMovie( ) or duplicateMovieClip(
) function, and can be changed at any time using the
swapDepths( ) function. Each programmatically
generated clip's depth (sometimes
called its z-index) determines its position
within a particular stack of programmatically generated clips.
The depth of a clip may be any integer and
is measured from the bottom up, so -1 is lower than 0; 1 is higher
than (i.e., in front of) depth 0; depth 2 is higher still, and so on.
When two programmatically generated clips occupy the same position on
screen, the one with the greater
depth value is rendered in front of the
other.
Layers are single-occupant dwellings. Only one clip may occupy a
layer in the stack at a time -- placing a clip into an occupied
layer displaces (and deletes) the layer's previous occupant.
It's okay for there to be gaps in the depths of clips; you can
have a clip at depth 0, another at depth 500, and a third one at
depth 1000. There's no performance hit or increase in memory
consumption that results from having gaps in
your depth assignments.