forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsendToBack.as
More file actions
25 lines (19 loc) · 690 Bytes
/
sendToBack.as
File metadata and controls
25 lines (19 loc) · 690 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;
/**
* Sends the DisplayObject to the back of the display list. The <code>forward</code> parameter can be used to bring the DisplayObject forward a few levels from the back.
* @param object the DisplayObject to reorder
* @param forward the number of levels from the back of the display list
* @return the new index of the DisplayObject
*/
public function sendToBack(object:DisplayObject, forward:uint = 0):int
{
if (!object.parent)
return -1;
var index:int = clamp(forward, 0, object.parent.numChildren - 1);
object.parent.setChildIndex(object, index);
return index;
}
}