Tutorial details:
Written 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) {
Yup, it's really that easy. If you can say "Hey Blue! Swap depths with Red!" then you can learn to use swap depths. Unfortunately simplicity generally brings with it ungainlyness and uselessness (at least in my tutorials it does). There is pretty much no practicle application for the Simple Swap movie, and it is detined to walk the world without an application for eternity. However Complex Swap (the first example movie in this tutorial) is quite a useful and interesting little movie, so let's move on.