forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbringToFront.as
More file actions
25 lines (20 loc) · 728 Bytes
/
bringToFront.as
File metadata and controls
25 lines (20 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package utils.display
{
import flash.display.DisplayObject;
import utils.number.clamp
/**
* Brings the DisplayObject to the front of the display list. The <code>back</code> parameter can be used to pull the DisplayObject back a few levels from the front.
* @param object the DisplayObject to reorder
* @param back the number of levels from the front of the display list
* @return the new index of the DisplayObject
*/
public function bringToFront(object:DisplayObject, back:uint = 0):int
{
if (!object.parent)
return -1;
var index:int = object.parent.numChildren - (back + 1);
index = clamp(index, 0, object.parent.numChildren - 1);
object.parent.setChildIndex(object, index);
return index;
}
}