Blog Post RSS ?

Blogs » Flash » Quick and Easy Depth Tricks
 

Quick and Easy Depth Tricks


  • Save to
    Del.icio.us

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:

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!

This post has 10 responses so far

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

     
  2. A. White… it’s called the internet.

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

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

     
  4. the bring to front method is extremely slow.

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

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

     
  7. Nice find, thanks

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

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

     
  10. sorry,
    import mx.behaviors.DepthControl;

     

Sponsored Links

Leave a response

You are not logged in, log in with your SitePoint Forum username and password.

-OR- Post Anonymously

* Make sure any code samples are escaped (i.e. ‘<b>’ becomes ‘&lt;b&gt;’).

If not logged in, your comments will be placed in a moderation queue. This means your comment may not appear until one of our moderators approves it.

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Logo Design, Web page Design and more!

99designs

  • Custom logo designs created ‘just for you’.
  • Pick the design you like best.
  • Only pay if you’re satisfied with the result.

Want More Traffic?

Get up to five quotes from qualified SEO specialists, with no obligation!

Get A Free SEO Quote Now!