5 Replies Latest reply on Jul 12, 2006 6:35 AM by cjwprostar.

    Tab Navigator not loading all tabs at start

    cjwprostar.
      I have a tab navigator with a dataGrid in one tab and another dataGrid in another and when I double click the dataGrid in tab 1 I want it to go to tab 2 and set the selected item or dataGrid1 to dataGrid2. The problem is when I double click on the dataGrid, and havent navigated to tab 2 before. This gives "TypeError: Error #1009: Cannot access a property or method of a null object reference." The tabNavigator's creationPolicy="all" and the function that is called on doubleClick is

      private function GotoNext():void{
      if(firstDataGrid.selectedItem!=null){
      myTabNavigator.selectedIndex=1;
      secondDataGrid.selectedItem=firstDataGrid.selectedItem;
      }
      }

      This works if I first click on the 2nd tab then click back on the 1st tab, but not if I just double click.

      Any help would be appreciated.
      Thanks,
      Chris
        • 1. Re: Tab Navigator not loading all tabs at start
          inlineblue Level 1
          By default, all containers use deferred instantiation (ie. create only when requested), which doesn't work in your case. If you want the TabNavigator to create all its children up front, set creationPolicy="all".
          • 2. Tab Navigator not loading all tabs at start
            cjwprostar. Level 1
            quote:

            Originally posted by: cjwprostar.
            ... The tabNavigator's creationPolicy="all" and ...


            Here's a working example that has this problem..

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Script>
            <![CDATA[
            import mx.collections.XMLListCollection;

            public var xmlOne:XML=
            <root>
            <data>
            <name>Foo</name>
            <type>Number</type>
            </data>
            <data>
            <name>Bar</name>
            <type>String</type>
            </data>
            </root>;

            public var xmlTwo:XML=
            <root>
            <data>
            <name>Foo</name>
            <type>Number</type>
            </data>
            <data>
            <name>Bar</name>
            <type>String</type>
            </data>
            </root>;
            [Bindable]
            public var sourceOne:XMLListCollection=new XMLListCollection(new XMLList(xmlOne));
            [Bindable]
            public var sourceTwo:XMLListCollection=new XMLListCollection(new XMLList(xmlTwo));

            public function GotoNext():void{
            if(dgOne.selectedItem!=null){
            tabNav.selectedIndex=1;
            trace(dgOne.selectedItem);
            trace(dgTwo.selectedItem);
            dgTwo.selectedItem=dgOne.selectedItem;
            trace(dgTwo.selectedItem);
            trace("--------------------------");
            }
            }
            ]]>
            </mx:Script>

            <mx:TabNavigator id="tabNav" creationPolicy="all" left="20" right="20" top="20" bottom="20">
            <mx:Panel id="tabOne" label="Tab 1" width="100%" height="100%">
            <mx:DataGrid dataProvider="{sourceOne.child('data')}" width="100%" height="100%" doubleClickEnabled="true" id="dgOne" doubleClick="GotoNext();">
            <mx:columns>
            <mx:DataGridColumn headerText="Column 1" dataField="name"/>
            <mx:DataGridColumn headerText="Column 2" dataField="type"/>
            </mx:columns>
            </mx:DataGrid>
            </mx:Panel>
            <mx:Panel id="tabTwo" label="Tab 2" width="100%" height="100%">
            <mx:DataGrid dataProvider="{sourceOne.child('data')}" id="dgTwo" width="100%" height="100%">
            <mx:columns>
            <mx:DataGridColumn headerText="Column 1" dataField="name"/>
            <mx:DataGridColumn headerText="Column 2" dataField="type"/>
            </mx:columns>
            </mx:DataGrid>
            </mx:Panel>
            </mx:TabNavigator>

            </mx:Application>
            • 3. Re: Tab Navigator not loading all tabs at start
              peterent Level 2
              In the example code above, the TabNavigator does not have creationPolicy="all". When I took the code below and ran it, I also got the error. When I added creationPolicy="all" to the TabNavigator, the problem went away.
              • 4. Re: Tab Navigator not loading all tabs at start
                cjwprostar. Level 1
                Ah sorry I forgot to include that.
                I managed to fix it somehow but I don't know exactly what fixed it. Probably one of the changes I made to my three datagrids/lists.
                Thanks for the help.
                • 5. Re: Tab Navigator not loading all tabs at start
                  cjwprostar. Level 1
                  Weird..this problem still comes up randomly..don't know why. Anyways I have another similar problem in the edited code in the above post. When you double click on dgOne, it does what it is supposed to, but if you first click to sort dgTwo and then double click dgOne it messes up and sets the selected item to null.

                  Thanks for any help,
                  Chris