- Home
- Tutorials
- Flash
- Intermediate
- Swap Depths

Page 1 of 2
Jesse Stratford
Jesse lives and works in Melbourne Australia. He is the Cofounder of http://ActionScript.org. A Flash enthusiast, teacher, author, freelancer and speaker Jesse's main focus nowadays is managing http://ActionScript.org, but he enjoys participating actively in community and the wider Flash scene when he has time.
View all articles by Jesse StratfordWritten by: Jesse Stratford
Time: 10 - 20 minutes
Difficulty Level: Intermediate
Requirements: Flash 5, artistic flare (ACME brand)
Topics Coverred: .swapDepths(), _name and _target properties
Assumed knowledge: Button actions, basic Actionscript: drag and drop operations, variables and paths, substring().
Download the source file for the above movie. (Zipped, PC .fla file).
In this tutorial we will discus the swapDepths movie clip operator of Flash 5. This operator allows us to adjust the Z indexing (the third dimension which controls the virtual 'depth' of an object on the stage). The example above shows the most common usage I can muster for such an operator: window arrangement and positioning. So let's get into it!
We'll start off with the basics. Take a look at the Simple Swap movie below. Download the source if you like.
You will notice that when you click the button the two ugly colored boxes 'swap' their order such that the one which was lowest and partially invisible becomes higher and dominant over the other. This is the most simple example of swapping depths I could think of. It's not made to be pretty :o)
Being a simple example, the code and structure are also simple. If you download the source for the above movie you will see it has only 3 elements: the button and the 2 boxes which are movie clip objects. The red box has an instance name of 'red', can you guess what the blue box is called? Now the button has the following code:
on (release) {
blue.swapDepths(red);
}

