0

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?

zero323
  • 322,348
  • 103
  • 959
  • 935
Julia
  • 151
  • 3
  • 11
  • You can pass data into the view; which is the second property of the pushView method. You can make that data a string representing the state you want the view to be in and when the view is activated set it to that state. I'm not sure how I feel about this approach, as--in theory--one view should not know details about the other. – JeffryHouser May 23 '13 at 13:30
  • Would the code look like this: `navigator.pushView(TheSecondView, 'currentState="SpecificState"');` – Julia May 23 '13 at 13:38
  • In addition, how would you get this string to "activiated" in TheSecondView? – Julia May 23 '13 at 13:38
  • The code would look like `navigator.pushView(TheSecondView, 'SpecificState')` . In the a viewActivated http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/View.html#event:viewActivate event listener; do something like this: `currentState = data;` – JeffryHouser May 23 '13 at 13:57
  • Can you call "currentState=data;" in viewActivated? I tried doing this (and it doesn't work, I get syntax errors): `` – Julia May 23 '13 at 14:34
  • Create a method, l9ike you did for the creationComplete event. What are you syntax errors? – JeffryHouser May 23 '13 at 14:42
  • 1
    I put currentState=data; into a method and it now works. Thanks! – Julia May 23 '13 at 14:44
  • I added a formal answer then – JeffryHouser May 23 '13 at 15:11

1 Answers1

1

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;
}
JeffryHouser
  • 39,401
  • 4
  • 38
  • 59