This tutorial shows you how to use the swapDepths function.

Think of a scenario where you have 3 pictures aligned one on top of the other, and you want to move the picture that underlies the top image. There are many ways to do this in Flash, and here, we’ll use the swapDepths feature.

Download the sample files here.

1. In the above example I’ve used three rectangular movielips. I have given each one instance names: "red", "blue", and "green".

2. These are the actions I’ve applied to each button:

Blue button:

on (press){;}

Red button:

on (press){;}

Green button:

on (press){;}





This refers to the instance of the movie clip whose depth is swapped by the instance specified in myMovieClip. Both instances must have the same parent movie clip.


This refers to the number specifying the depth level where MovieClip is to be placed.

This swaps the stacking, or z order (depth level), of the specified instance (MovieClip) with either:

  • the movie that’s specified by the target parameter, or
  • the movie that currently occupies the depth level specified in the depth parameter.

Both movies must have the same parent movie clip. Swapping the depth level of movie clips has the effect of moving one movie in front of, or behind, the other. And if a movie is tweening when this method is called, the tweening is stopped.

Georgina has more than fifteen years' experience writing and editing for web, print and voice. With a background in marketing and a passion for words, the time Georgina spent with companies like Sausage Software and cemented her lasting interest in the media, persuasion, and communications culture.

No Reader comments

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.