有没有一种方法来检查的DisplayObject A是的DisplayObject B的后裔? [英] Is there a way to check if DisplayObject A is a descendant of DisplayObject B?

查看:163
本文介绍了有没有一种方法来检查的DisplayObject A是的DisplayObject B的后裔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够快速检查一个给定的DisplayObject是后代(不是在继承感 - 也就是孩子,孙子,曾孙,玄孙孙子,等)。另外的DisplayObject的

似乎有不为原生的方式做到这一点,我只能想到两个方法来实现它:

  1. 创建所有的嵌套循环的母亲。似乎有点,我不知道,错了吗?
  2. 分派冒泡事件的'孩子',并检查潜在的父接收它。

我试图后者目前,但将AP preciate一些投入。我想创建一个很好的工具静电功能,例如:

 的静态公共职能isDescendantOf(子:的DisplayObject,父:级DisplayObjectContainer):布尔{

    VAR isDescendant:布尔= FALSE;

    //执行一些神奇的
    //检查返回true
    //如果它是一个后代

    返回isDescendant;
}
 

解决方案

神圣角驼鹿,事件的...

  parent.contains(子);
 

见<参考href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html#contains%28%29">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:

  1. Create the mother of all nested loops. Seems a bit, I dunno, wrong?
  2. 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().

这篇关于有没有一种方法来检查的DisplayObject A是的DisplayObject B的后裔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆