1

次のような基本的な MXML セットアップがあるとします。

<Item id="parent">
    <Frame>
        <mx:Image/>
    </Frame>
</Item>

Image 要素の属性を、親 Item の孫 (子の子) として参照するにはどうすればよいですか? getChildAt() への 2 つの呼び出しをデイジーチェーン接続してみました。

parent.getChildAt(0).getChildAt(0)

しかし、次のエラーが表示されます。

Error: Call to a possibly undefined method getChildAt through a reference with static type flash.display:DisplayObject.

孫要素を呼び出す適切な方法は何ですか?

4

1 に答える 1

2

getChildAt()関数は DisplayObject を返します

getChildAt()

したがって、次のように型キャストする必要があります。

DisplayObjectContainer(parent.getChildAt(0)).getChildAt(0)
于 2013-02-07T15:34:05.773 に答える