3 Replies Latest reply on Sep 17, 2007 11:29 PM by Senor_Roberto

    TabNavigator: Adding Tab Dynamic

    wy790289
      Hi,

      I would like to create an application that is using a TabNavigator to show different information (tabs) when user press different buttons. I create a button and call a function to add a tab into tabnavigator to show a custom control (base on Panel). I try it and the program can add the tab and show the correct information. But I don't know how to add the label on the created tab. Also, can it be any simple method to check it the information is shown already in tabnavigator?

      The function is listed below:
      private function addUserRequest():void {
      var ur:DisplayObject = tabControl.addChild(new userRequest);
      var tabNdx:int; // Tab Index

      tabNdx = tabControl.getChildIndex(ur);
      tabControl.selectedIndex = tabControl.getChildIndex(ur);
      return;
      }
      //end of function

      Thanks a lot!
      Wilson
        • 1. Re: TabNavigator: Adding Tab Dynamic
          Senor_Roberto Level 1
          If UserRequest is a custom component which extends Panel, the label of the panel will be used as the label of the tab when it's added to the TabNavigator.
          In order to do this you'll need to define ur as a compatible type which has a label property, i.e. as a Panel or as a UserRequest (or whatever it's called):

          var ur:Panel = new UserRequest(); // UserRequest is subclass of Panel so compatible.
          ur.label = "A Label"; // I can set this because I am a panel
          tabControl.addChild(ur);

          I'm not sure I understand your last question. Do you want to know if the tab with that label already exists?
          • 2. Re: TabNavigator: Adding Tab Dynamic
            wy790289 Level 1
            Hi Senor,

            Very thanks for your help!

            You're right! The last question I want to know is to find any ways to prevent the same function will be called more than 1 time. In the above case, we assume the UserRequest is a data entry form and I want to only let one copy of the form displayed every time. If user open the form that already opened, the program will show a warning or jump to the opened form directly.

            Thanks you for your help again!
            Wilson
            • 3. Re: TabNavigator: Adding Tab Dynamic
              Senor_Roberto Level 1
              Can't you just check whether UserRequest is set whenever addUserRequest is called?