我希望能够快速检查给定的 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;
}