addChildAt method

  1. @override
void addChildAt (DisplayObject child, int index)
override

Adds a child DisplayObject to this DisplayObjectContainer at the specified index position.

An index of 0 represents the back (bottom) of the display list for this DisplayObjectContainer.

If you add a child object that already has a different display object container as a parent, the object is removed from the child list of the other display object container.

Implementation

@override
void addChildAt(DisplayObject child, int index) {
  if (index < 0 || index > _children.length) {
    throw new ArgumentError("The supplied index is out of bounds.");
  } else if (child == this) {
    throw new ArgumentError(
        "An object cannot be added as a child of itself.");
  } else if (child.parent == this) {
    _addLocalChildAt(child, index);
  } else {
    child.removeFromParent();
    _throwIfAncestors(child);
    _children.insert(index, child);
    _setChildParent(child);
  }
}