我希望能够快速检查一个给定的DisplayObject是后代(不是在继承感 - 也就是孩子,孙子,曾孙,玄孙孙子,等)。另外的DisplayObject的
似乎有不为原生的方式做到这一点,我只能想到两个方法来实现它:
创建所有的嵌套循环的母亲。似乎有点,我不知道,错了吗? 分派冒泡事件的'孩子',并检查潜在的父接收它。我试图后者目前,但将AP preciate一些投入。我想创建一个很好的工具静电功能,例如:
的静态公共职能isDescendantOf(子:的DisplayObject,父:级DisplayObjectContainer):布尔{
VAR isDescendant:布尔= FALSE;
//执行一些神奇的
//检查返回true
//如果它是一个后代
返回isDescendant;
}
解决方案
神圣角驼鹿,事件的...
parent.contains(子);
见DisplayObjectContainer.contains().
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;
}
解决方案
Holy horned moose, event for that...
parent.contains(child);
See reference for DisplayObjectContainer.contains().