views:

219

answers:

1

Hi I am trying to create the transition between states. The first state transition works fine(state1=>state2), but the second one is acting weird(state2=>state3). After clicks the button to change state2=>state3, some text areas which are belong to state2 show up and stay on the screen. I am not sure why. I would appreciate it if someone here can help me out.

My code.

<?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>
+1  A: 

Your code sample looks incomplete. I think we'll need to see more than just the state and transitions. IF you can provide a full running sample that would be helpful.

I assume this is a sample issue, but in your current code, the transitions toStates are not created in the document. Since you have three states, you may want to add a 'fromState' and explicitly design the transition from / to each state.

If I had to guess, you probably need to specify the 'includeIn' property on the relevant components. You can use a comma delimited list of states, something like this:

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

Where the first component would appear in state a, the second would appear in state b and c, and the third component would appear in state a and c.


Updated Posters Code:

    <?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>
www.Flextras.com
thank you. I just updated my code. I did have my includeIn in my component. I even uninstall my flex and reinstall because I thought this is flex's glitch...The animation totally threw me off..but +1..first
Jerry
BTW. All these strange behavior happens just because I add "<s:AddAction targets"...">" If I remove 1 of them, the animation works right except they all play at the same time...
Jerry
Can you provide runnable code to demonstrate the problem? For example, your states are defined as a, b, and c but the components only refer to a state named "addRecommend" and transitions. When I added a state named addRecommend I got an error about an undefined property named dataGrid.
www.Flextras.com
sorry about the confusion..I just created totally new codes with the same scenario. It's easier and less codes...please see update. Thanks again!!!
Jerry
I added updated code to my answer. I played around with it a bit; and things were happening oddly inconsistently for reasons I couldn't explain. I specified the alphaFrom and alphaTo on the fades and specified includeIn states for the two buttons and everything seemed to start working. Since you're doing a parallel effect, I'm not sure why you need the AddAction tag. If you want more, you'll have to elaborate on what your specific issue was. "weird" is hard to debug.
www.Flextras.com
wow. You are the man! I follow your steps and things are working fine now. Although I have to add includeIn="state1, state2, state3" in my buttons (kind of weird). My issue was that when I click the btn2 to change the states, the btn1 was disappeared (btn1 should be in all states) and one of the label show up(not suppose to). I have to use AddAction tag because I want the fade happens after the move. Sequence tag won't do the trick. Could you explain why I have to include all states to make the animation work? Anyway, Thank you so much!!!!!
Jerry
I was able to replicate the same things, with btn1 disappearing and label3 showing up in State3. I have no explanation for these. If you want fade to happen after the move, a sequence should work.
www.Flextras.com
allright. Thanks a lot! :D
Jerry