Search code examples
actionscript-3apache-flexairflex4.6

Flex/AIR Mobile: TabbedViewNavigator selectedIndex not working


I have a Mobile Project in FB 4.6 with a TabbedViewNavigator. I have 4 buttons at the bottom, which are ViewNavigators, and act as the Tabs. For this instance, lets say the tabs are labeled, HOME, ADD, DELETE, and ABOUT. I am running into the following situation:

  1. User presses the ADD tab.
  2. In the ADD screen, user clicks on several links which takes them away from the ADD tab's firstView and to a new view all together. For this instance, let's say the active view is called PlayersView.
  3. User now clicks another tab, for example HOME.
  4. User decides to go back to the ADD tab. However, upon pressing the ADD tab, the user is taken to the last view, which in this case was the PlayersView.

How can I have the functionality changed so that upon pressing a Tab, the user is ALWAYS taken to the firstView property of that tab. As referenced above, this is not happening. I have tried creating an IndexChangeEvent listener on the tabbedNavigator and then changing the tabbedNavigator's selectedIndex, however this doesn't work.

protected function tabbedviewnavigatorapplication1_applicationCompleteHandler(event:FlexEvent):void {

      this.tabbedNavigator.addEventListener(IndexChangeEvent.CHANGE,onIndexChange);
}


protected function onIndexChange(event:IndexChangeEvent):void {

      this.tabbedNavigator.selectedIndex = event.newIndex;
      trace(' THIS DOESN'T WORK');
}

Any help is appreciated. Thanks, in advance.


Solution

  • In your code, when you set

    tabbedNavigator.selectedIndex 
    

    you switch between different ViewNavigators, not between different Views inside a ViewNavigator.

    As I understand it, you are trying to stay within a single ViewNavigator stack and select the first View.

    Let's say you have:

    <s:navigators>
        <s:ViewNavigator id="addSomethingNavigator" firstView="views.AddView"/>
        <s:ViewNavigator id="deleteSomethingNavigator" firstView="views.DeleteView"/>
    </s:navigators>
    

    You can pop to a specific ViewNavigator's first View like so:

    addSomethingNavigator.popToFirstView();