1

状態間の遷移を作成しようとしています。最初の状態遷移 (state1=>state2) は正常に機能しますが、2 番目の状態遷移は正常に機能しません (state2=>state3)。ボタンをクリックして state2=>state3 に変更すると、state2 に属するいくつかのテキスト領域が表示され、画面に残ります。理由はわかりません。ここの誰かが私を助けてくれれば幸いです。

私のコード。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
        <![CDATA[
            protected function btn1_clickHandler(event:MouseEvent):void
            {
                currentState="state2";
            }

            protected function btn2_clickHandler(event:MouseEvent):void
            {
                currentState="state3";
            }



        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>





    <s:states>
        <s:State name="state1"/>
        <s:State name="state2"/>
        <s:State name="state3"/>
    </s:states>


    <s:transitions>

        <s:Transition toState="state2" >
            <s:Parallel>

            <s:Move targets="{[btn1,btn2]}" />
            <s:AddAction targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}" /> 
            <s:Fade targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}"/>

            </s:Parallel>

        </s:Transition>
        <s:Transition toState="state3" >
            <s:Fade targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}"/>

        </s:Transition>

    </s:transitions>


    <s:Label y="10" text="label1" id="label1" includeIn="state2" />
    <s:TextInput y="30" id="textInput1" includeIn="state2" />
    <s:Label y="50" text="label1" id="label2" includeIn="state2" />
    <s:TextInput y="70" id="textInput2" includeIn="state2" />
    <s:Label y="90" text="label1" id="label3" includeIn="state2" />
    <s:TextInput y="120" id="textInput3" includeIn="state2" />



    <s:Button y="180" y.state2="350" label="btn1" id="btn1" click="btn1_clickHandler(event)"/>
    <s:Button y="250" y.state2="550" label="btn2" id="btn2" click="btn2_clickHandler(event)"/>



</s:Application>
4

1 に答える 1

2

コード サンプルが不完全に見えます。状態と遷移だけでなく、それ以上のものを見る必要があると思います。役立つ完全な実行サンプルを提供できる場合。

これはサンプルの問題だと思いますが、現在のコードでは、toStates への遷移がドキュメントに作成されていません。3 つの状態があるため、「fromState」を追加して、各状態から / への遷移を明示的に設計することができます。

おそらく、関連するコンポーネントで「includeIn」プロパティを指定する必要があると思います。次のように、コンマで区切られた状態のリストを使用できます。

<s:Component includeIn="a" />
<s:Component includeIn="b,c" />
<s:Component includeIn="a,c" />

最初のコンポーネントが状態 a で表示される場合、2 番目のコンポーネントは状態 b および c で表示され、3 番目のコンポーネントは状態 a および c で表示されます。


更新されたポスター コード:

    <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
        <![CDATA[
            protected function btn1_clickHandler(event:MouseEvent):void
            {
                currentState="state2";
            }

            protected function btn2_clickHandler(event:MouseEvent):void
            {
                currentState="state3";
            }



        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>



    <s:states>
        <s:State name="state1"/>
        <s:State name="state2"/>
        <s:State name="state3"/>
    </s:states>


    <s:transitions>

        <s:Transition toState="state2" >
            <s:Parallel>

                <s:Move targets="{[btn1,btn2]}" />
                <!--<s:AddAction targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}" /> -->
                <s:Fade targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}" alphaFrom="0" alphaTo="1"/>

            </s:Parallel>

        </s:Transition>
        <s:Transition toState="state3" >
            <s:Parallel>
<!--                <s:Move targets="{[btn1,btn2]}" />-->
                <!--<s:RemoveAction targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}" /> -->
                <s:Fade targets="{[label1,label2,label3,textInput1,textInput2,textInput3]}" alphaFrom="1" alphaTo="0"/>
            </s:Parallel>

        </s:Transition>

    </s:transitions>


    <s:Label y="10" text="label1" id="label1" includeIn="state2" />
    <s:TextInput y="30" id="textInput1" includeIn="state2" />
    <s:Label y="50" text="label2" id="label2" includeIn="state2" />
    <s:TextInput y="70" id="textInput2" includeIn="state2" />
    <s:Label y="90" text="label3" id="label3" includeIn="state2" />
    <s:TextInput y="120" id="textInput3" includeIn="state2" />



    <s:Button y="180" y.state2="350" includeIn="state1,state2,state3" label="To State 2" id="btn1" click="btn1_clickHandler(event)"/>
    <s:Button y="250" y.state2="550" includeIn="state1,state2,state3" label="To State 3" id="btn2" click="btn2_clickHandler(event)"/>



</s:Application>
于 2010-06-19T12:38:26.787 に答える