removeChildren method

  1. @override
void removeChildren ([int beginIndex, int endIndex ])
override

Removes all child DisplayObject instances from the child list of this DisplayObjectContainer instance.

Optionally, an index range may be specified with beginIndex and endIndex.

The parent property of the removed children is set to null, and the objects are garbage collected if no other references to the children exist.

Implementation

@override
void removeChildren([int beginIndex, int endIndex]) {
  int length = _children.length;
  int i1 = beginIndex is int ? beginIndex : 0;
  int i2 = endIndex is int ? endIndex : length - 1;
  if (i1 > i2) {
    // do nothing
  } else if (i1 < 0 || i1 >= length || i2 < 0 || i2 >= length) {
    throw new ArgumentError("The supplied index is out of bounds.");
  } else {
    for (int i = i1; i <= i2 && i1 < _children.length; i++) {
      removeChildAt(i1);
    }
  }
}