1

特定のDisplayObjectが別のDisplayObjectの子孫(つまり、子、孫、曽孫、曽孫など)であるかどうかをすばやく確認できるようにしたいと思います。

これを行うためのネイティブな方法はないようで、私はそれを達成するための2つの方法しか考えられません。

  1. すべてのネストされたループの母を作成します。少しそうです、私は知らない、間違っていますか?
  2. '子'でバブリングイベントをディスパッチし、潜在的な'親'がそれを受信するかどうかを確認します。

現在後者を試していますが、いくつかの入力をいただければ幸いです。素敵なユーティリティ静的関数を作成したいと思います。例:

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;
}
4

2 に答える 2

7

聖なる角のあるムース、そのためのイベント...

parent.contains(child);

DisplayObjectContainer.contains()のリファレンスを参照してください。

于 2010-10-26T11:31:11.353 に答える
0

動作しましたが、厄介な匿名関数を使用しています。

改善できるかしら?

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;
}
于 2010-10-26T11:23:49.667 に答える