Most Flash introductions spend the bulk of their time on sequential structures--frames and scenes--and to some extent on component structures such as shapes, buttons, and movie clips. Less tends to be said about a different kind of structure: the kind that allows us to keep several things present but visually distinct--in other words, hierarchy.
There are three levels of hierarchical structure in Flash: levels, layers, and depths.
- Levels
- Levels constitute the highest or most general form of hierarchy in Flash.
Levels are virtual slots into which Flash movies are loaded.
The first movie loaded into your project occupies Level 0, the second
Level 1, etc. Unless you've used the loadMovie() command to
load more than one movie at a time, you probably haven't given
much thought to levels.
- Layers
- Layers provide the middle level of Flash structure, and are probably
the most familiar hierarchical device for most users.
Layers are also the only form of hierarchy that is visually represented
in the Flash authoring interface.
Every Flash movie has at least one level, and it may have many more.
Unlike levels, which organize the relationships among multiple
movies, layers are entirely contained within a movie (that is,
within a single .fla or .swf file).
- Depths
- Depths make up the finest and perhaps most obscure level of
Flash hierarchy. Depth distinctions arise in two cases: when
movie clips are installed on different layers,
or when multiple movie clips are installed within the same layer.
Flash assigns each clip a unique depth value.
This value is not represented in the authoring interface,
except when it involves layer placement, but when you
test or play your movie depth differences are reflected by
the visual overlapping of objects. Objects are higher depths
appear above objects at lower depths.
Using the swapDepths() method of movie clips, you may
change the stacking order either within or across layers.
The movie below shows stacking depth in action. The red bouncing object (#1) is scripted to swap levels with any of the other three movie clips when it intersects them. If you watch closely, you'll see this clip slip behind its neighbor when this happens. To make the effect more visible I've given each movie clip a different height and width to imitate visual perspective: higher numbered clips seem further away or lower in the virtual stack. When the #1 clip intersects, it appears to drop down to its neighbor's depth.
The source file for this example may be found in MMShare/depthExample. It's called depthExample.fla.
