contains method

bool contains (DisplayObject child)

Determines whether the specified DisplayObject is a child of this DisplayObjectContainer instance or the instance itself.

The search includes the entire display list including this DisplayObjectContainer instance. Grandchildren, great-grandchildren, and so on each return true.

Implementation

bool contains(DisplayObject child) {
  while (child != null) {
    if (child == this) return true;
    child = child.parent;
  }
  return false;
}