4 Replies Latest reply on Jun 9, 2011 10:39 PM by Kumar Pratik

    how can i find the label of all the tabs of a tab navigator??

    Kumar Pratik Level 1

      I have a tab navigator which has three fixed tabs and dynamically i am creating few tabs. Before creating a tab i wanted to know which all tabs are currently open, basically the name of all the tabs which are open.

       

      Please let me know how can i achieve this.

       

      Thanks

        • 1. Re: how can i find the label of all the tabs of a tab navigator??
          _spoboyle Level 4

          extended from the TabNavigator example in the API docs

          <?xml version="1.0" encoding="utf-8"?>
          <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                 xmlns:s="library://ns.adobe.com/flex/spark" 
                                 xmlns:mx="library://ns.adobe.com/flex/mx"
                                 minWidth="955" minHeight="600"
                                 creationComplete="init()">
              
              <fx:Script>
                  <![CDATA[
                      private function init():void
                      {
                          for (var i:int = 0; i < tn.numElements; i++)
                          {
                              var btn:Button = tn.getTabAt(i);
                              trace(btn.label);
                          }
                      }
                  ]]>
                  
              </fx:Script>
              <s:layout>
                  <s:VerticalLayout/>
              </s:layout>
              
              <s:Panel title="TabNavigator Container Example"
                       width="75%" height="75%"
                       horizontalCenter="0" verticalCenter="0">
                  <s:VGroup left="10" right="10" top="10" bottom="10">
                      <s:Label width="100%" color="blue"
                               text="Select the tabs to change the panel."/>
                      
                      <mx:TabNavigator id="tn"  width="100%" height="100%">
                          <!-- Define each panel using a VBox container. -->
                          <mx:VBox label="Panel 1">
                              <mx:Label text="TabNavigator container panel 1"/>
                          </mx:VBox>
                          
                          <mx:VBox label="Panel 2">
                              <mx:Label text="TabNavigator container panel 2"/>
                          </mx:VBox>
                          
                          <mx:VBox label="Panel 3">
                              <mx:Label text="TabNavigator container panel 3"/>
                          </mx:VBox>
                      </mx:TabNavigator>
                      
                      <s:Label width="100%" color="blue"
                               text="Programmatically select the panel using a Button control."/>
                      
                      <s:HGroup>
                          <mx:Button label="Select Tab 1" click="tn.selectedIndex=0"/>
                          <mx:Button label="Select Tab 2" click="tn.selectedIndex=1"/>
                          <mx:Button label="Select Tab 3" click="tn.selectedIndex=2"/>
                      </s:HGroup>
                  </s:VGroup>
              </s:Panel>
              
          </s:WindowedApplication>
          
          • 2. Re: how can i find the label of all the tabs of a tab navigator??
            Kumar Pratik Level 1

            This is not working in flex 3.. Please help

            • 3. Re: how can i find the label of all the tabs of a tab navigator??
              _spoboyle Level 4
              <?xml version="1.0"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                  xmlns:local="*"
                                  creationComplete="init()">
                   
                   <mx:Script>
                        <![CDATA[
                             private function init():void
                             {
                                  for (var i:int = 0; i < tn.numChildren; i++)
                                  {
                                       var btn:Button = tn.getTabAt(i);
                                       trace(btn.label);
                                  }
                             }
                        ]]>
                   </mx:Script>
                   
                   <mx:Panel title="TabNavigator Container Example"
                              width="75%" height="75%"
                              horizontalCenter="0" verticalCenter="0">
                        <mx:VBox left="10" right="10" top="10" bottom="10">
                             <mx:Label width="100%" color="blue"
                                        text="Select the tabs to change the panel."/>
                             
                             <mx:TabNavigator id="tn"  width="100%" height="100%">
                                  <!-- Define each panel using a VBox container. -->
                                  <mx:VBox label="Panel 1">
                                       <mx:Label text="TabNavigator container panel 1"/>
                                  </mx:VBox>
                                  
                                  <mx:VBox label="Panel 2">
                                       <mx:Label text="TabNavigator container panel 2"/>
                                  </mx:VBox>
                                  
                                  <mx:VBox label="Panel 3">
                                       <mx:Label text="TabNavigator container panel 3"/>
                                  </mx:VBox>
                             </mx:TabNavigator>
                             
                             <mx:Label width="100%" color="blue"
                                        text="Programmatically select the panel using a Button control."/>
                             
                             <mx:HBox>
                                  <mx:Button label="Select Tab 1" click="tn.selectedIndex=0"/>
                                  <mx:Button label="Select Tab 2" click="tn.selectedIndex=1"/>
                                  <mx:Button label="Select Tab 3" click="tn.selectedIndex=2"/>
                             </mx:HBox>
                        </mx:VBox>
                   </mx:Panel>
              </mx:Application>
              
              
              • 4. Re: how can i find the label of all the tabs of a tab navigator??
                Kumar Pratik Level 1

                Thanks I am able to solve this now.. Actually in Flex3 we getTabAt is not supported so I am using getChildAt with neccessary modification.

                 

                Thanks,

                Pratik