public DisplayObjectX removeChildAt(int index, bool dispose = false) { if (index >= 0 && index < numChildren) { DisplayObjectX child = mChildren[index]; child.simpleDispatch(EventX.REMOVED); if (stage != null) { DisplayObjectContainerX container = child as DisplayObjectContainerX; if (container != null) { container.broadcastEventWith(EventX.REMOVED_FROM_STAGE); } else { child.simpleDispatch(EventX.REMOVED_FROM_STAGE); } } child.setParent(null); index = mChildren.IndexOf(child); if (index >= 0) { mChildren.RemoveAt(index); } if (dispose) { child.dispose(); } return(child); } else { throw new RankException("Invalid child index"); } }
public virtual DisplayObjectX addChildAt(DisplayObjectX child, int index) { int numChildren = mChildren.Count; if (index >= 0 && index <= numChildren) { if (child.parent == this) { setChildIndex(child, index); // avoids dispatching events } else { child.removeFromParent(); // 'splice' creates a temporary object, so we avoid it if it's not necessary if (index == numChildren) { mChildren.Add(child); } else { mChildren.Insert(index, child); } child.setParent(this); //child.dispatchEventWith(EventX.ADDED, true); if (stage != null) { DisplayObjectContainerX container = child as DisplayObjectContainerX; if (container != null) { //递归上去; //container.simpleDispatch(EventX.ADDED_TO_STAGE); } else { child.simpleDispatch(EventX.ADDED_TO_STAGE); } } } return(child); } else { throw new RankException(); } }