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:
bringForward(target:MovieClip)
sendBackward(target:MovieClip)
bringToFront(target:MovieClip)
sendToBack(target:MovieClip):Void
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!
Related posts:
- Better Selections In Photoshop With Quick Masks The Quick Mask in Photoshop offers a really easy way...
- Selections In Photoshop, Part 4: Tips & Tricks In the final part of our series on Selections in...
- Five Photoshop Layers Speed Tricks Jennifer shows you five quick tricks to speed up your...
- Why You Should Be Using Press Releases to Promote Your Business In the first of a two-part series on press releases,...
- Quick and Easy Graphing with the Google Chart API The Google Chart API makes creating simple charts and graphs...






Is there any place that documents all of the mx.behaviors in detail?
May 24th, 2004 at 5:02 pm
A. White… it’s called the internet.
All joking aside, a detaile breakdown of the behaviours would be insanely sweet.
May 25th, 2004 at 3:11 pm
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.)
May 26th, 2004 at 4:38 am
the bring to front method is extremely slow.
June 17th, 2004 at 8:01 am
Anyone else having speed issues?, as i’m unable to reproduce the speed issue here!
June 17th, 2004 at 10:27 am
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.
http://www.inlandoffice.com/prototype
The tween class can be found at:
http://laco.wz.cz/tween
Best,
Aaron
June 24th, 2004 at 1:36 pm
Nice find, thanks
November 5th, 2004 at 11:00 am
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!
regards,
mediamogul
March 22nd, 2005 at 8:20 am
that the class have to be import should be mentioned
mx.behaviors.DepthControl;mx.behaviors.DepthControl.sendToBack(myMC);
//…bringToFront(myMC);
// ….sendBackward(myMC);
// ….bringForward(myMC);
August 16th, 2006 at 7:46 pm
sorry,
import mx.behaviors.DepthControl;August 16th, 2006 at 7:47 pm