Quick and Easy Depth Tricks

By | | Flash

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!

Written By:

sgrosvenor

 

{ 10 comments }

mjchael August 16, 2006 at 7:47 pm

sorry,
import mx.behaviors.DepthControl;

mjchael August 16, 2006 at 7:46 pm

that the class have to be import should be mentioned
mx.behaviors.DepthControl;
mx.behaviors.DepthControl.sendToBack(myMC);
//…bringToFront(myMC);
// ….sendBackward(myMC);
// ….bringForward(myMC);

mediamogul March 22, 2005 at 8:20 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

ktec November 5, 2004 at 11:00 am

Nice find, thanks

zakcoop June 24, 2004 at 1:36 pm

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

sgrosvenor June 17, 2004 at 10:27 am

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

_lennel_ June 17, 2004 at 8:01 am

the bring to front method is extremely slow.

Si May 26, 2004 at 4:38 am

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.)

dawgbone May 25, 2004 at 3:11 pm

A. White… it’s called the internet.

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

A. White May 24, 2004 at 5:02 pm

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

Comments on this entry are closed.