Search code examples
flashapache-flexstateflex-spark

Flex: How do you use pushView() to access a specific state of a certain viewClass?


From a viewClass called TheFirstView I want to "move" to a viewClass called TheSecondView with the state SpecificState.

I know how to get to the TheSecondView, the code is: navigator.pushView(TheSecondView);

Is there a way to specify using pushView() that you want to "move" to SpecificState in TheSecondView?


Solution

  • You can pass data into the view; which is the second property of the pushView method, like this:

    navigator.pushView(TheSecondView, 'SpecificState')
    

    Inside the view, you can listen for the viewActivated event to change the state:

    Add the listener:

    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" viewActivate="onViewActivated()">
    

    And in some ActionScript code, implement the listener like this:

    protected function onViewActivated():void{
     currentState=data;
    }