removeChildAt<T extends GDisplayObject> method
Removes the child at the specified index from this container.
If index
is invalid, a RangeError
will be thrown.
If dispose
is true
, the removed child will also be disposed.
Returns the removed child object.
Implementation
T removeChildAt<T extends GDisplayObject>(int index, [bool dispose = false]) {
if (index >= 0 && index < children.length) {
requiresRedraw();
final child = children[index];
child.$onRemoved?.dispatch();
if (stage != null) {
child.$onRemovedFromStage?.dispatch();
child.removedFromStage();
if (child is GDisplayObjectContainer) {
_broadcastChildrenRemovedFromStage(child);
}
}
child.$setParent(null);
index = children.indexOf(child);
if (index >= 0) {
children.removeAt(index);
}
if (dispose) {
child.dispose();
}
return child as T;
}
throw 'Invalid child index';
}