Set Highest depth of an object – Important Classes for games in AS 3.0

December 23rd, 2011 by aabhaanjan

images

[xml]
package
{
import flash.display.MovieClip;

/**
* …
* @Description : In development of game we somtime need to put a particular object in highest Depth, means
* above of all other objects of same parent. In that case we can use this class.
* @author Aava
*/
public class KeepInTopDepthClass extends MovieClip
{

private var _parent:Object
private var _ObjRef:MovieClip
/*
* @Description : Here we are passing the parent object as the parameter of constructor.
*/

public function KeepInTopDepthClass(__parent:Object) {
_parent = __parent;
}
/*
* @Description : By Calling this function with the parameter of that object which you want to be in top , you
* can make that object on above of all others.
*/
public function setTheObjectAtTopDepth(__Obj:MovieClip):void {
_ObjRef = __Obj;
var topPosition:uint = _parent.numChildren – 1;
_parent.setChildIndex(_ObjRef, topPosition-1);
}

}

}
[/xml]