Flash: Depth Control

April 28th, 2005 by Luis

Maybe is old news but I didn't know about it. Basically I found the mx.behaviors.DepthControl in one of the example files provided with MX Pro.

It is a class that provides you with some static functions for depth sorting and depth information.

Classpath: mx.behaviors.DepthControl

Class methods:

  • sendToBack
  • bringToFront
  • sendBackward
  • bringForward
  • trackDepths
  • orderFunc
  • getInstanceAtLowest
  • getInstanceAtHighest
  • getInstanceLowerThan
  • getInstanceHigherThan

See some documentation here

More about Depths in Flash:

Small DepthManager Utility to use when you export as Flash 6:

Actionscript:
  1. /**
  2. ******************************************
  3. * based on <a href="http://proto.layer51.com/d.aspx?f=833">Fernando Flórez</a> getNextDepth  AS1 prototype
  4. @class (SINGLETON): DepthManager
  5. @author: luis@lessrain.com
  6. PUBLIC METHODS
  7. getNextDepth
  8. getInstance
  9. @usage:
  10. var dm:DepthManager = DepthManager.getInstance ();
  11. createEmptyMovieClip ("one", 2);
  12. createEmptyMovieClip ("two", dm.getNextDepth (this));
  13. trace ("the next free depth is: " + dm.getNextDepth (this));
  14. ******************************************
  15. */
  16.  
  17. class DepthManager
  18. {
  19.     private static var _oInstance:DepthManager = null;
  20.    
  21.     private function DepthManager ()
  22.     {
  23.     }
  24.    
  25.     public static function getInstance ():DepthManager
  26.     {
  27.         if (_oInstance == null) {
  28.             DepthManager._oInstance = new DepthManager ();
  29.         }
  30.         return DepthManager._oInstance;
  31.     }
  32.    
  33.     public function getNextDepth (mClip:MovieClip):Number
  34.     {
  35.         var t:Number = -Infinity;
  36.         var i:Number;
  37.         for (var i in mClip) {
  38.             if (mClip[i].getDepth () != null && mClip[i]._parent == mClip) {
  39.                 t = Math.max (t, mClip[i].getDepth ());
  40.             }
  41.         }
  42.         return (t> -1) ? ++t : 0;
  43.     }
  44.    
  45. }


NOTE:If you export the movie as flash 7 there is not need of the DepthManager utility , you can simply use the built in movieclip method getNextHighestDepth().

One Response to “Flash: Depth Control”

  1. Ruchira Says:

    you are saying (then in april 2005) that you didnt know this!!
    i came across this feature in flash 8, and today only i found this behavior class, sad that it is not listed in the standard classes.
    thanks to you to list some methods here…

Leave a Reply