swapChildren method
Swaps the positions of two children.
Throws an ArgumentError if child1
or child2
are not children of this
container. If child1
and child2
are the same object, nothing happens.
Example:
var container = GDisplayObjectContainer();
var child1 = GSprite();
var child2 = GQuad();
container.addChild(child1);
container.addChild(child2);
container.swapChildren(child1, child2);
This will swap the positions of child1 and child2 in container.
See also:
-
swapChildrenAt, which swaps the positions of two children based on their indices instead of their references.
-
setChildIndex, which changes the position of a child in the display list based on its index.
Implementation
void swapChildren(GDisplayObject child1, GDisplayObject child2) {
final idx1 = getChildIndex(child1);
final idx2 = getChildIndex(child2);
if (idx1 == -1 || idx2 == -1) {
throw ArgumentError('Not a child of this container');
}
swapChildrenAt(idx1, idx2);
}