Quick and Easy Depth Tricks

I was rooting around in the Flash MX 2004′ sock drawer and stumbled across a rather nifty AS file (DepthControl.as) buried in the installation directory; a little further exploratory work and i was pleasantly surprised to find some very simple methods for depth shuffling (kinda cool if you’re into game or windowed application development).

Here’s the list of publically available functions for the class:


And having created a simple movie clip with a linkage identifier of depthTest, I added the following code to the first frame of the timeline allowing simple press-release functionality to the duplicated MCs on the stage

for (i=0; i<15; i++) { duplicateMovieClip("depthTest", ["depthTest"+i], i+5); _root["depthTest"+i]._x = 50+(i*10); _root["depthTest"+i]._y = 50+(i*10); _root["depthTest"+i].onPress = function() { mx.behaviors.DepthControl.bringForward(this); }; _root["depthTest"+i].onRelease = function() { mx.behaviors.DepthControl.sendBackward(this); }; }

Now when I need to include any depth manipulation in my applications, I can simply include the class and call the functions through the prototype chain!