我希望能够快速检查给定的DisplayObject是否是后代(而不是继承意义上的)。(子女、孙女、曾孙、曾孙等)另一个DisplayObject。
似乎没有一种本土化的方法可以做到这一点,我只能想出两种方法来实现它:
我正在尝试后者,但希望能提供一些信息。我想创建一个很好的实用程序静态函数,例如:
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;
}发布于 2010-10-26 11:31:11
神圣的角驼鹿,为了这件事.
parent.contains(child);有关DisplayObjectContainer.contains(),请参阅参考资料。
发布于 2010-10-26 11:23:49
好的,我让它起作用了,但是它使用了一个讨厌的匿名函数。
想知道它是否可以改进?
static public function isDescendantOf(child:DisplayObject, parent:DisplayObjectContainer):Boolean {
const HELLO:String = "hello";
var isDescendant:Boolean = false;
parent.addEventListener(HELLO, function(e:Event):void {
isDescendant = true;
});
child.dispatchEvent(new Event(HELLO, true, false));
return isDescendant;
}https://stackoverflow.com/questions/4022966
复制相似问题