Flash: Depth Control
April 28th, 2005 by LuisMaybe 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:
- Depths - How they work in Flash.
- Quick and Easy Depth Tricks.
- Reloading after swapDepths.
- TextField swapDepths.
- Remove Objects from the stage with swapDepths.
Small DepthManager Utility to use when you export as Flash 6:
Actionscript:
- /**
- ******************************************
- * based on <a href="http://proto.layer51.com/d.aspx?f=833">Fernando Flórez</a> getNextDepth AS1 prototype
- @class (SINGLETON): DepthManager
- @author: luis@lessrain.com
- PUBLIC METHODS
- getNextDepth
- getInstance
- @usage:
- var dm:DepthManager = DepthManager.getInstance ();
- createEmptyMovieClip ("one", 2);
- createEmptyMovieClip ("two", dm.getNextDepth (this));
- trace ("the next free depth is: " + dm.getNextDepth (this));
- ******************************************
- */
- class DepthManager
- {
- private static var _oInstance:DepthManager = null;
- private function DepthManager ()
- {
- }
- public static function getInstance ():DepthManager
- {
- if (_oInstance == null) {
- DepthManager._oInstance = new DepthManager ();
- }
- return DepthManager._oInstance;
- }
- public function getNextDepth (mClip:MovieClip):Number
- {
- var t:Number = -Infinity;
- var i:Number;
- for (var i in mClip) {
- if (mClip[i].getDepth () != null && mClip[i]._parent == mClip) {
- t = Math.max (t, mClip[i].getDepth ());
- }
- }
- return (t> -1) ? ++t : 0;
- }
- }
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().



April 8th, 2006 at 11:21 pm
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…