Swapping movie clip depths

To swap the depths of two movie clips on the same timeline, use MovieClip.swapDepths(). The following examples show how two movie clip instances can swap depths at runtime.

To swap movie clip depths:

  1. Create a new Flash document called swap.fla.
  2. Draw a blue circle on the Stage.
  3. Select the blue circle, and then select Modify > Convert to Symbol.
  4. Select the Movie clip option, and then click OK.
  5. Select the instance on the Stage, and then type first_mc into the Instance Name text box in the Property inspector.
  6. Draw a red circle on the Stage, and then select Modify > Convert to Symbol.
  7. Select the Movie clip option, and then click OK.
  8. Select the instance on the Stage, and then type second_mc into the Instance Name text box in the Property inspector.
  9. Drag the two instances so that they overlap slightly on the Stage.
  10. Select Frame 1 of the Timeline, and then type the following code into the Actions panel:
    first_mc.onRelease = function() {
            this.swapDepths(second_mc);
        };
        second_mc.onRelease = function() {
            this.swapDepths(first_mc);
        };
    
  11. Select Control > Test Movie to test the document.

    When you click the instances on the Stage, they swap depths. You'll see the two instances change which clip is on top of the other clip.

For more information, see swapDepths (MovieClip.swapDepths method) in the ActionScript 2.0 Language Reference.