0

ボタン付きのパネルがあります。ボタンをクリックすると、パネルが「State2」の状態になり、さらに 2 つのボタンがパネルに追加されます。状態の変更中に、最初にパネルのサイズを変更してから、新しく追加された 2 つのボタンを表示するようにしたいので、状態の変更にトランジションを適用しました。

私の質問は:

HBox 内の addChild タグのすぐ下に 2 つのボタンを配置すると、正常に動作します。ただし、同じコード (2 つのボタンを含む HBox) で新しいコンポーネントを作成し、新しいコンポーネントをパネルに追加すると (コメントされたコードの Comp)、サイズ変更効果は表示されません。

誰かがこれを修正する方法を教えてもらえますか? 前もって感謝します。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">

    <mx:Script>
        <![CDATA[
            protected function button1_clickHandler(event:MouseEvent):void
            {
                currentState="State2";
            }
        ]]>
    </mx:Script>

    <mx:transitions>
        <mx:Transition>
            <mx:Sequence targets="{[comp,panel1]}">
                <mx:Resize target="{panel1}" />
                <mx:AddChildAction />
            </mx:Sequence>
        </mx:Transition>
    </mx:transitions>

    <mx:states>
        <mx:State name="State2">
            <mx:AddChild relativeTo="{panel1}" position="lastChild">
                <mx:HBox id="comp">
                    <mx:Button label="B" />
                    <mx:Button label="C" />
                </mx:HBox>
                <!--<local:Comp id="comp" />-->
            </mx:AddChild>

        </mx:State>
    </mx:states>

    <mx:Panel layout="horizontal" borderThickness="1" borderStyle="solid" id="panel1" title="AB">
        <mx:Button label="A" click="button1_clickHandler(event)"/>
    </mx:Panel>
</mx:Application>
4

1 に答える 1

0

<mx:AddChild>タグは一度に 1 つのコンポーネントしか処理できないと思います。

<mx:AddChild>以下のコードのように、カスタム コンポーネントを別のタグに分離すると、適切なサイズ変更効果が得られます。

<mx:AddChild relativeTo="{panel1}" position="lastChild">
      <mx:HBox id="comp">
           <mx:Button label="B" />
           <mx:Button label="C" />
           <!-- Don't put your custom component here. --> 
      </mx:HBox>
</mx:AddChild> 
<!-- Use separated AddChild. Still add to same relativeTo object  -->           
<mx:AddChild relativeTo="{panel1}" position="lastChild">
     <local:Comp id="comp2" />
</mx:AddChild>

あなたが欲しいものを手に入れたことを願っています。

于 2010-04-19T12:47:21.933 に答える