3 Replies Latest reply on May 4, 2011 4:37 AM by sumit.king7

    Is it possible to dynamically add children to a TabNavigator

    kris456 Level 1

      Is it possible to dynamically add & delete children to a TabNavigator. If so how do I do it ?

      Say I have a tabnavigator control with

       

          <mx:TabNavigator x="70" y="97" width="200" height="200">
              <mx:Canvas label="Tab 1" width="100%" height="100%" id="tab">
              </mx:Canvas>
          </mx:TabNavigator>
      

       

      How can I add a tab to the tabnavigator ?

      Please Help.

        • 1. Re: Is it possible to dynamically add children to a TabNavigator
          ShardulSingh Level 3

          Hi,

          Yes it is possible to add tabs dynamically to TabNavigator.Pls find the code below.Let me know if you have any issue.

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

           

          <?xml version="1.0"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

          <mx:Script>

          <![CDATA[

          import mx.controls.Label;

          import mx.containers.VBox;

          private function onCreationComplete():void

          {

           

          var vbox1: VBox= new VBox();

          vbox1.label ="Tab 1";

          var lbl1: Label = new Label()

          lbl1.text ="Panel1";

          vbox1.addChild(lbl1);

          tabNavigator.addChild(vbox1);

           

          var vbox2: VBox= new VBox();

          vbox2.label ="Tab 2";

          var lbl2: Label = new Label()

          lbl2.text ="Panel 2";

          vbox2.addChild(lbl2);

          tabNavigator.addChild(vbox2);

           

          var vbox3: VBox= new VBox();

          vbox3.label ="Tab 3";

          var lbl3: Label = new Label()

          lbl3.text ="Panel 3";

          vbox3.addChild(lbl3);

          tabNavigator.addChild(vbox3);

          }

           

           

           

           

           

          private var counter : Number= 0;

          private function addNewTab():void

          {

          var vbox: VBox= new VBox();

          vbox.label ="Tab "+ counter.toString();

          var lbl: Label = new Label()

          lbl.text ="Panel "+ counter.toString();

          vbox.addChild(lbl);

          tabNavigator.addChild(vbox);

          counter ++;

          }

           

          ]]>

          </mx:Script>

          <mx:Panel title="Add Tabs Dynamically" height="90%" width="90%" >

          <mx:TabNavigator id="tabNavigator" width="100%" height="100%" creationComplete="onCreationComplete()"/>

          <mx:Button click="addNewTab()" label="Add new Tab"/>

          </mx:Panel>

           

          </mx:Application>

           

           

           

           

           

          with Regards,

          Shardul Singh Bartwal

          • 3. Re: Is it possible to dynamically add children to a TabNavigator
            sumit.king7

            i am able to add tabs dynamically but:

             

            1) how to get focus on the last added tab.