I would like to be able to quickly check if a given DisplayObject is a descendant (not in the inheritance sense - ie. child, grandchild, great-grandchild, great-great-grandchild, etc.) of another DisplayObject.
There doesn't seem to be a native way to do this and I can only think of two ways to achieve it:
- Create the mother of all nested loops. Seems a bit, I dunno, wrong?
- Dispatch a bubbling event at the 'child' and check if the potential 'parent' receives it.
Am trying the latter now, but would appreciate some input. I'd like to create a nice utility static function, eg:
static public function isDescendantOf(child:DisplayObject, parent:DisplayObjectContainer):Boolean {
var isDescendant: Boolean = false;
// perform some magical
// check that returns true
// if it is a descendant
return isDescendant;
}