setChildIndex method

void setChildIndex(
  1. DisplayObject child,
  2. int index
)

Changes the position of an existing child in this DisplayObjectContainer to the new index.

This affects the layering of child objects.

When you use the setChildIndex method and specify an index position that is already occupied, the only positions that change are those in between the display object's former and new position. All others will stay the same. If a child is moved to an index LOWER than its current index, all children in between will INCREASE by 1 for their index reference. If a child is moved to an index HIGHER than its current index, all children in between will DECREASE by 1 for their index reference.

Implementation

void setChildIndex(DisplayObject child, int index) {
  if (index < 0 || index >= _children.length) {
    throw ArgumentError('The supplied index is out of bounds.');
  } else if (child.parent != this) {
    throw ArgumentError(
        'The supplied DisplayObject must be a child of the caller.');
  } else {
    _addLocalChildAt(child, index);
  }
}