/// <summary> /// Removes a child at a certain index. Children above the child will move down. /// </summary> public DisplayObject RemoveChildAt(int index, bool dispose = false) { if (index >= 0 && index < _children.Count) { SetRequiresRedraw(); DisplayObject child = _children[index]; child.InvokeRemoved(); if (Stage != null) { child.BroadcastRemovedFromStageEvent(this); } child.Parent = null; int newIndex = _children.IndexOf(child); // index might have changed in event handler if (newIndex != -1) { _children.RemoveAt(newIndex); } if (dispose) { child.Dispose(); } return(child); } throw new IndexOutOfRangeException("Invalid child index"); }
/// <summary> /// Disposes all resources of the display object. /// GPU buffers are released, event listeners are removed, filters and masks are disposed. /// </summary> public virtual void Dispose() { Added = null; AddedToStage = null; Removed = null; RemovedFromStage = null; EnterFrame = null; Touch = null; KeyUp = null; KeyDown = null; _filter?.Dispose(); _mask?.Dispose(); Mask = null; // clear 'mask._maskee', just to be sure. }