Quick and Easy Depth Tricks

By sgrosvenor

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!

  • A. White

    Is there any place that documents all of the mx.behaviors in detail?

  • dawgbone

    A. White… it’s called the internet.

    All joking aside, a detaile breakdown of the behaviours would be insanely sweet.

  • Si

    Have you tried any of the Friends of Ed references? I’ve got the Flash MX Actionscript Reference by them guys and it’s a great resource. I’m sure the MX2004 edition is even better! (BTW, I’m not connected to FoE – just really impressed with their stuff.)

  • _lennel_

    the bring to front method is extremely slow.

  • sgrosvenor

    Anyone else having speed issues?, as i’m unable to reproduce the speed issue here!

  • zakcoop

    I haven’t noticed speed issues except … I have noticed that when other press/release actions are assigned to the same button things can pause for a moment before executing.

    I’m working on a new web site and have found these functions to be invaluable. Though, I sure would love a way to cross-fade the depth change of layers. I’ve simply worked around this using an equally useful (perhaps more) tween class that provides great functions as well.


    The tween class can be found at:




  • ktec

    Nice find, thanks

  • mediamogul

    THANK YOU!!!!!
    I’ve been struggling with bringing movieclips to the front for days now… :P
    I had it working fine in AS 1.0, player #6, but in AS 2.0 it suddenly seemed impossible. Until now. :D
    once again, cheers, you made my day!

  • mjchael

    that the class have to be import should be mentioned
    // ….sendBackward(myMC);
    // ….bringForward(myMC);

  • mjchael

    import mx.behaviors.DepthControl;

Get the latest in Front-end, once a week, for free.