tags:

views:

61

answers:

2

I have a TabNavigator that has a handful of children. The flow of the application allows the possibility of a user leaving the screen with this TabNavigator, then returning. When this happens, a method called on show of the parent canvas sets selectedChild to the first tab. When actually tested, the TabNavigator returns showing the text on the first tab, but the tab that is highlighted is whatever tab the user was on just before leaving.

Here is some pseudo-code that looks something like what I have:

<mx:Canvas show="init()">
<mx:Script>
<![CDATA[
    private function init():void {
        menutabs.selectedChild = tab1;
    }
 ]]>
</mx:Script>
<mx:TabNavigator id="menutabs">
    <mx:VBox id="tab1" label="Tab 1"><mx:Label text="First Tab Text" /></mx:VBox>
    <mx:VBox id="tab2" label="Tab 2"><mx:Label text="Second Tab Text" /></mx:VBox>
    <mx:VBox id="tab3" label="Tab 3"><mx:Label text="Third Tab Text" /></mx:VBox>
</mx:TabNavigator>
</mx:Canvas>

So what I am experiencing, for example, is going to another canvas with the application, having been on Tab 2, then returning to this canvas to see the text "First Tab Text" but the highlighted tab along the top is "Tab 2." I have tried handfuls of variations within the init() method of invalidateDisplayList, validateNow, and so on, with no change in the outcome.

Any ideas welcome.

A: 

Did you observe that 'selectedChild' is an actual property of ViewStack, and not TabNavigator? Since TabNavigator can be considered as ViewStack + TabBar, setting selectedChild has no effect on TabBar.

I suggest to use 'selectedIndex' than to set selectedChild. You can obtain the selectedIndex from the Container itself, using getChildIndex()

Sai Prasad
Regretably, when I replaced menutabs.selectedChild = tab1; with menutabs.selectedIndex = 0; the result was the same.
Wade
A: 

I left out a bit of information. My init() method does more than just selectedChild, and I think this other stuff, that didn't necessarily need to run every time, was what was screwing up the re-drawing of the tabs. So I created a new goHomeTab() method to call on show, and call my init() method only on initialize. All seems to be fine now. Thanks.

Wade