6 Replies Latest reply on Feb 1, 2010 3:07 PM by John Hall

    Tabnavigator selectedIndex issue

    John Hall Level 4

      I have a TabNavigator. The script controlling portion of it is:


                  private function init():void{
                      tabNavBar.selectedIndex = 2;


      this works fine as the third tab is selected upon creationComplete of the component.


      However, if I send in an int via scripting, nothing changes.


                  public function changeTab( e:FormEvent ):void {
                      Alert.show("Event value passed in is " + e.tabIndex.toString());           // Alerts Event value passed in is 0
                      Alert.show("Starting value is " + tabNavBar.selectedIndex.toString());  // Alerts starting value is -1 (no children??)
                      tabNavBar.selectedIndex = e.tabIndex;
                      Alert.show("Tab is now" + tabNavBar.selectedIndex.toString());          // Alerts Tab is now 0 (correct but doesn't change)


      Things I've tried:




      e.tabIndex as int;


      Other suggestions?



        • 1. Re: Tabnavigator selectedIndex issue
          David_F57 Level 5



          the following code changes the tabnavigator programmatically, when you press the tabbar the change event then sets the tabnavigator to match . When you set the selected index it should just work, are you doing this from a popup window as that may have an effect on how the component updates(note: I'm using the latest sdk).


          you could try setting the update flag(this shouldn't really have any effect), tabnav.updateCompletePendingFlag=true; but without the full code its hard to say what the problem is.



          <?xml version="1.0" encoding="utf-8"?>

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"




          import mx.collections.ArrayCollection;

          import mx.events.FlexEvent;

          import spark.events.IndexChangeEvent;


          [Bindable] private var myArr:ArrayCollection = new ArrayCollection(['1','2','3']);


          protected function application1_creationCompleteHandler(event:FlexEvent):void


          tabnav.selectedIndex = 1;




          protected function buttonbar1_changeHandler(event:IndexChangeEvent):void


          tabnav.selectedIndex = event.newIndex;





          <!-- Place non-visual elements (e.g., services, value objects) here -->


          <mx:TabNavigator id="tabnav" x="174" y="191" width="579" height="254">

          <s:NavigatorContent label="Tab 1" width="100%" height="100%">


          <s:NavigatorContent label="Tab 2" width="100%" height="100%">


          <s:NavigatorContent label="Tab 3" width="100%" height="100%">



          <s:ButtonBar x="204" y="78" dataProvider="{myArr}" change="buttonbar1_changeHandler(event)"/>



          • 2. Re: Tabnavigator selectedIndex issue
            John Hall Level 4

            If I put a button near the tab navigator and control it there it's fine. It's solely when the index is passed in as an event property, which is pretty strange. I'll see if I can make a pared down repro but it's one of those awful things where you're 40 files into a project in the nightly builds and this little thing pops up. Creating a repro almost entails creating a new app since I'm also using the Mate framework. ARgh.

            • 3. Re: Tabnavigator selectedIndex issue
              John Hall Level 4

              OK. Created a little repro if anyone has time to take a look. This zip file is an export out of FlashBuilder so you should be able to import directly.


              Since it does seem to make a difference these days, I'm using build 13654 on this right now.  In fact, with the latest build the test file couldn't find sparkSkins and I wasn't patient enough to debug for a repro case.


              Thanks for any insights.

              • 4. Re: Tabnavigator selectedIndex issue
                Flex harUI Adobe Employee

                Mate is creating a new instance of the TabNavigator in order to handle the


                • 5. Re: Tabnavigator selectedIndex issue
                  John Hall Level 4

                  What a great clue. That's a programming error on my part then. Thanks!! I could have scratched my head for a while.

                  • 6. Re: Tabnavigator selectedIndex issue
                    John Hall Level 4

                    One line of code and it's all fixed. Thanks so much as usual.