forked from as3/as3-utils
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathremoveChild.as
More file actions
33 lines (32 loc) · 991 Bytes
/
removeChild.as
File metadata and controls
33 lines (32 loc) · 991 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
26
27
28
29
30
31
32
33
package utils.display
{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
/**
* Removes a child from the parent without throwing errors if the child or parent is null
* or if the child isn't a child of the specified parent.
*
* @param child The child DisplayObject to remove.
* @param parent The parent to remove the child from. If none is specified, the function
* attempts to get the parent from the child's <code>parent</code> property.
* @returns Boolean True if the child was removed from the parent. False if something prevented it.
*
* @author Mims Wright
*/
public function removeChild(child:DisplayObject, parent:DisplayObjectContainer = null):Boolean
{
if (child) {
if (!parent) {
if (!child.parent) { // if parent and child.parent are null
return false;
}
parent = child.parent;
}
if (parent == child.parent) {
parent.removeChild(child);
return true;
}
}
return false;
}
}