tags:

views:

188

answers:

2

I need to find out what state i am currently viewing. Lets suppose...

<mx:states>
        <mx:State name="state1">

            </mx:AddChild>
        </mx:State>

        <mx:State name="state2">

            </mx:AddChild>
        </mx:State>

</mx:states>

Once i login in my application, the state1 appears, but on refresh of page it disappears again.

I am having the session value as of now, just need to check if the session is true then hold the current state or get back to the default one.

+1  A: 

You can determine the current state from the component's currentState property. In flex 3 default state is empty string. When you refresh the browser page (who does that when using a flash application?) you actually reload the entire flash application, meaning all your components will be recreated. So if you check your session, you then need to assign currentState of your component accordingly.

So based on your sample code, if you're viewing state 2, currentState of your component that defines the state, will now be "state2". This is the value you specified as the name of your second state. To set the viewing to first state, you can do

component.currentState = "state1";

as that is the name of your first state. To go to default (initial) state, you would do:

component.currentState = "";

To verify that you're on second state, you would do

if (component.currentState == "state2")
  doSomething();

If your second state would be named "secondstate" instead of "state2", you'd be using:

if (component.currentState == "secondstate")
      doSomething();

At least that's the way for flex 3, because as I understand flex 4 introduces some changes related to states.

bug-a-lot
lets suppose i am viewing state 2, how can i know this... can i get this info through something like selectedIndex or other... can u help me a bit more
I've added use case code samples to my answer.
bug-a-lot
A: 

In agreement with above, here are some code samples:

In the component, you have to reference this.currentState or simply currentState:

private function checkCurrentState():void
{
    alert(this.currentState);
}

or, if you are debugging, simply use a trace() statement:

trace(this.currentState);
Eric Belair