3 Replies Latest reply on Apr 16, 2010 5:17 AM by brad carvey-kplRXI

    Instantiation of datagrid before it's displayed?

    brad carvey-kplRXI

      How can a datagrid be instantiated before it's displayed?  Seems simple, but I can't get it to work.  I put trace statement on the initialize and creationComplete methods and they only print trace statements when the datagrid is displayed.


      This is specifically what I am trying to do.


      I am using a tab navigator with the release version of Flex 4.  I have 6 tabs with advancedDatagrids on each tab.  The datagrids have images and lots of data (columns and rows of data).   At startup the first tab's datagrid is populated.  I want to instantiate the other datagrids in the other tabs, after the first tab and datagrid are displayed.  Currently, the datagrids only get instantiated when their tabs are selected.  There is up to a 10 second delay, while a datagrid loads with data and is displayed.


      I created a canvas under the TabNavigator and added an AdvancedDatagrid.  The AdvancedDatagrid is initialized and created when the tab is selected and the canvas is instantiated.


      I tried adding "imageTabCanvas = new Canvas" to the container's CreationComplete method that the TabNavigator was created in.  I then added "imageADG = new ImagesAdvancedDatagrid" to the same method.  I was trying to force instantiation of the datagrid, after the container for the tabNavigator was created.  I don't want to wait till the user clicks on the tab to instantiate the datagrid.


      I tried a bunch of stuff and can't get the datagrid to instantiate, until is is displayed.


      Any ideas what I am doing wrong?

        • 1. Re: Instantiation of datagrid before it's displayed?
          David_F57 Level 5



          You can set the creationpolicy of the tab navigator to all that way child items are instantiated strait away instead of after tab selection.




          1 person found this helpful
          • 2. Re: Instantiation of datagrid before it's displayed?
            brad carvey-kplRXI Level 1

            Thanks for the reply.


            I tried this.  After login into the site, the first thing I do is use an httpService to download a large xml file.  The file contains data for the datagrids, including paths to images and videos.  The next thing I do is to create array collections that are used as dataProviders for the different datagrids.


            The application mxml has components in this order login window, httpService, MainDividedBox.  The MainDividedBox contains the TabNavigator with the datagrids.  I only specify the creation policy for the TabNavigator, the other components including the main app, default to AUTO.  I add a bunch of trace statements to the initialize and creationcomplete methods, so I can see what happens when the application starts.



            Application preinitialized

            MainDividedBox initialized

            The TabNavigator canvas/datagrids get initialized

            TabNavigator initialized

            MainDividedBox initiated

            Application intialized


            Then an error

            TypeError: Error #1009: Cannot access a property or method of a null object reference.

            at com.ameritest.renderers::VideoContainerItemRenderer/set data()......


            The item renderer is looking for an image.  The path is in the imagesArrayCollection created from the xml by the httpService.  The code to generated the imagesArrayCollection is not called, until after a successful login, and we haven't even finished creating the application.


            This is why I was trying to instantiate the datagrids after the login and the first tabs datagrid was displayed.  While the user is looking at the first tab's datagrid, I want to start instantiating the next 4 tab's datagrids.


            I am confused why the second tab's datagrid, which has an item renderer in the first column has a null data error.  The first tab's datagrid and first in the MXML is not generating any null data errors.


            It seems like the datagrids can be created without the data being available from the arrayCollections, but the item renderer needs the data.  The error comes from the line of code that starts with "if"


            public function set data(value:Object):void


                _data = value;

                if (_data.source != null && _data.representativeImage != null)


                    _imgSource = _data.representativeImage;

                    _videoSource = _data.source;



            • 3. Re: Instantiation of datagrid before it's displayed?
              brad carvey-kplRXI Level 1

              I removed the item renderer and the datagrids were created, but not populated yet.

              The xml was then loaded.

              The arraycollections created.

              The datagrids then started populating themselves with data.


              I waited a bit then clicked on the tabs.  The datagids opened with data loaded and images displayed.


              I had thought there was an issue with data, that really was an issue with accessing an object before it was created.