6 Replies Latest reply on Nov 4, 2013 5:36 PM by huangxinghui

    Getting child of SuperTabNavigator/TabNavigator

    olegkon Level 1

      Hi,

       

      I have several components (Box with ID with AdvancedDataGrid) added as children to SuperTabNavigator.

      Need to get a handle to such child component to refresh its DataGrid's data

      (or possibly to close it and open another one like that with new data).

       

      So how can I get a handle to the child of SuperTabNavigator?

      And how can I check whether such Box with ID already exists in SuperTabNavigator or not?

       

      (I think, answer for TabNavigator would help too)


      --
      Thank you in advance,
      Oleg.
        • 1. Re: Getting child of SuperTabNavigator/TabNavigator
          huangxinghui Level 1

          if the handle is public, you can invoke like this SuperTabNavagator.boxID.handle

           

          can you give some example code

          • 2. Re: Getting child of SuperTabNavigator/TabNavigator
            olegkon Level 1

            OK, here is an essense of my code.

             

            var tabName:String = "Tab1";

            var tab:Box = new Box();

            tab.id = tabName;

            tab label = tabName;

             

            var gridPanel:DataPanel = new DataPanel();  // grid Panel with DataGrid (and some other data)

             

            tab.addChild(gridPanel);

             

            var dataTabs:SuperTabNavigator = new SuperTabNavigator();

             

            grids[tabName] = grid.gridDataProvider;  // grids is a Dictionary

             

            dataTabs.addChild(tab);

             

             

            //Now on some data receiving Event I need to do something like that:

            if (dataTabs.tab[id=tabName]   // if tab with that name exists in SuperTabNavigator

            && grids[tabName] ) {  // and

               grids[tabName] = grid.gridDataProvider;  // refresh that dataGrid' dataProvider with some new data (ArrayCollection)

            }

             

            How can I do that?

             

            TIA,

            Oleg.

            • 3. Re: Getting child of SuperTabNavigator/TabNavigator
              huangxinghui Level 1

              may be you can loop superTabNavigator's children and find the child which id is tabName.

               

              private function getChildByID(id:String, dataTabs:SuperTabNavigator):UIComponent { 

                   var n:int = dataTabs.children().length;

                   var gridPanel:UIComponent;

                   for (var i:int = 0; i < n; i++) {

                        gridPanel = dataTabs.getChildAt(i) as UIComponent;

                        if(gridPanel.id == tabName) {

                            return gridPanel;

                        }

                   }

                   return null;

              }

              • 4. Re: Getting child of SuperTabNavigator/TabNavigator
                olegkon Level 1

                Thank you for helping me.

                 

                Please look at that line:

                var n:int = dataTabs.children().length;

                 

                1) there is no such method as children() there

                2) closest to it is childDescriptors():Array, but it returns me null, even though I have some panels there.

                 

                Any suggestions?

                 

                 

                TIA,

                Oleg.

                • 5. Re: Getting child of SuperTabNavigator/TabNavigator
                  olegkon Level 1

                  it should be var n:int = dataTabs.numChildren;

                  but in any case:

                  gridPanel = dataTabs.getChildAt(i) as UIComponent;

                  returns NULL for every instance.

                  Any way to fix it?

                  • 6. Re: Getting child of SuperTabNavigator/TabNavigator
                    huangxinghui Level 1

                    sorry about the dataTabs.children().length, it should be dataTabs.numChildren

                     

                    i wrote a example and it works right.

                     

                    <?xml version="1.0" encoding="utf-8"?>
                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                                                            xmlns:ns="http://code.google.com/p/flexlib/"
                                                            backgroundColor="0xFFFFFF" creationComplete="init()">
                      
                              <mx:Script>
                                        <![CDATA[
                                                  import mx.containers.Box;
                                                  import mx.containers.VBox;
                                                  import mx.controls.Alert;
                                                  import mx.core.UIComponent;
                      
                                                  private function init():void {
                                                            var tab:Box;
                      
                                                            for (var i:int = 0; i < 3; i++)
                                                            {
                                                                      tab = new Box();
                                                                      tab.id = 'Tab' + i;
                                                                      tab.label = 'Tab' + i;
                                                                      dataTabs.addChild(tab);
                                                            }
                                                  }
                      
                                                  private function getChildById(id:String, tabs:SuperTabNavigator):UIComponent
                                                  {
                                                            var child:UIComponent;
                                                            for (var i:int = 0, n:int = tabs.numChildren; i < n; i++)
                                                            {
                                                                      child = tabs.getChildAt(i) as UIComponent;
                                                                      if (child.id == id)
                                                                      {
                                                                                return child;
                                                                      }
                                                            }
                                                            return null;
                                                  }
                      
                                                  protected function button1_clickHandler(event:MouseEvent):void
                                                  {
                                                            var child:UIComponent = getChildById('Tab2', dataTabs);
                                                            Alert.show(child.id);
                                                  }
                      
                                        ]]>
                              </mx:Script>
                      
                              <ns:SuperTabNavigator id="dataTabs" height="90%" width="90%">
                      
                              </ns:SuperTabNavigator>
                      
                              <mx:Button label="Get Tab2" click="button1_clickHandler(event)"/>
                    </mx:Application>
                    
                    
                    

                     

                    Hope help for you.

                     

                    Huang