Swap Depths
This is going to be relativly short because the tutorial is not very complex, but it will be helpful. Check out the examples at the end of the page to see what you will learn.
What does swapDepths do?
swapDepths will dynamically swap the depth of a movie clip, so you can bring MCs forwards or backwards in order. This can be useful for things where you may need to be in front of something at some point, and behind it at another. (NOTE: If you have played Alien Hominid on the console, one of the earlier levels has a few hedges where you are behind and then in front of, this is the same principle.)
How can I use swapDepths?
The following codes are depth related, and may help you if you are using swapDepths.
INSTANCE.swapDepths(target) - Swap INSTANCE with the instance of the MC that you will be swapping depths (eg this), and swap target with either an instance name or a number, the MC will swap depths with target.
INSTANCE.getDepth() - This will get the depth of the INSTANCE for use in your code.
_root.getNextHighestDepth() - This will get the next highest depth, for use in your code.
An example of swapDepths:
onClipEvent (enterFrame) {
thisDepth=this.getDepth(), otherDepth=_root.INSTANCE.getDepth();
if (_y>_root.INSTANCE._y && otherDepth>thisDepth) {
this.swapDepths(_root.INSTANCE);
}
if (_root.INSTANCE._y>_y && thisDepth>otherDepth) {
this.swapDepths(_root.INSTANCE);
}
}
That code is a basic swap depths code, where the MC the code is placed upon will be either in front or behind the INSTANCE movie clip.
Examples
Drag and drop the snowmen.
Move with the arrow keys around the block/wall.
Useful links
Google
Macromedia
Kirupa
Sup, bitches :)
