0

Below is a very simple example, randomly, if I click the step2 button the state will change but the Step 2 panel will not be there.

I suspect the children of the state are not getting created for some reason, which is why I set the itemCreationPolicy to "immediate", but it makes no difference

This is catastrophic for the application because the user is left in limbo and is forced to refresh

Any ideas, please?

 <s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" 
                       creationPolicy="all" currentState="step1">   
        <s:states>
            <s:State name="step1"/>
            <s:State name="step2"/>
        </s:states>
        <s:BorderContainer includeIn="step1" itemCreationPolicy="immediate">
            <s:Panel title="Step 1"/>  
        </s:BorderContainer>
        <s:BorderContainer includeIn="step2" itemCreationPolicy="immediate">
            <s:Panel title="Step 2"/>  
        </s:BorderContainer>
        <s:Button title="step1" click="{this.setCurrentState('step1',true)}"/>
        <s:Button title="step2" click="{this.setCurrentState('step2',true)}"/>
    </s:BorderContainer>
Gary Benade
  • 507
  • 4
  • 16

2 Answers2

1

I've just tested it with Flex SDK 4.1 and it works without changing the creation policy. Clicking "step 2" successfully changes the state.

BTW: You don't need the curly braces in you click event handler...

<?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" currentState="step1">

    <s:layout>
        <s:VerticalLayout/>
    </s:layout>

    <s:states>
        <s:State name="step1"/>
        <s:State name="step2"/>
    </s:states>

    <s:BorderContainer includeIn="step1">
        <s:Panel title="Step 1"/>
    </s:BorderContainer>

    <s:BorderContainer includeIn="step2">
        <s:Panel title="Step 2"/>
    </s:BorderContainer>

    <s:Button label="step1" click="setCurrentState('step1', true)"/>
    <s:Button label="step2" click="setCurrentState('step2', true)"/>
</s:Application>
Gerhard Schlager
  • 3,155
  • 1
  • 31
  • 53
  • The problem is random, it will work 20 times and then suddenly the issue will pop up. If I leave the app for an hour and then come back it seems to happen more frequently (GC?) Thanks for the curly braces tip – Gary Benade Nov 23 '10 at 06:21
1

Seems that you use old / pre-release version of Flex 4 SDK. It might be a good idea to update to 4.1.0 - last stable version.

P.S: Writing this.setCurrentState('step1',true) is not the best idea. I suggest to use currentState = 'step1' - it is the official way of state changing.

Maxim Kachurovskiy
  • 2,992
  • 2
  • 21
  • 24
  • I am using flex 4.1.0 What is the issue with using setCurrentState, the API docs suggest it? – Gary Benade Nov 23 '10 at 06:17
  • The [documentation](http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_3.htmldocumentation) says: "You can also change a component's view state by calling the setCurrentState() method of the UIComponent class. Use this method when you do *not* want to apply a transition that you have defined between two view states." So, in most cases you can just use `currentState = 'foo'`. – Gerhard Schlager Nov 23 '10 at 19:47