9 Replies Latest reply on Aug 12, 2010 5:17 AM by flex4

    how flex will create instances for components ?

    flex4 Level 2

      Hi All,

       

       

                 I have a small doubt about the creation of instances of components.

       

       

                          I have a scenario where i have a datagrid with 100 records. each record having one itemrenderer i.e check box. so as per 100 records there may be 100 checkboxes in datagrid... But In My datagrid the visible records are only 20.. and i need scroll the datagrid..

       

                 so what my questions is weather flex creates all 100 checkbox instances for 100 records or it will create only visible 20 checkboxes for 20 records..?  I think u r getting my point?

       

       

                         Same scenario will applicable to viewstack also??

       

       

       

                 Explanation appreciable..

        • 1. Re: how flex will create instances for components ?
          BhaskerChari Level 4

          @Flex4,

           

          Flex creates all 100 checkbox instances for 100 records ...Infact when you specify the dataprovider for a DataGrid it will render and create instances

           

          for all the items in your DataProvider...at the same time....but not for only the visible items..

           

           

          If you take TileList control in Flex...it will create instances only for the visible items first and as you scroll by the instances for the next visible items

           

          are created....Where in contrary to this ...in a Tile container used with a Repeater component creates all the insatnces at the same time...for visible and

           

          invisible items as well....

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: how flex will create instances for components ?
            flex4 Level 2

                          Thanks for reply..

              

             

                                      u mean it will create all 100 record in datagrid.  Ok can u tell me about viewstack components also please?

            • 3. Re: how flex will create instances for components ?
              BhaskerChari Level 4

              @Flex4 ..Yes it will create all the 100 records in DataGrid...

               

               

              Coming to ViewStack...the creation varies on the creationPolicy property of the ViewStack container...

               

              Containers with multiple views, such as the ViewStack and Accordion, do not immediately create all of their descendants, but only those descendants that are visible in the initial view. Flex defers the instantiation of descendants that are not initially visible until the user navigates to a view that contains them. The following containers have multiple views and, so, are defined as navigator containers:

              ViewStack
              TabNavigator
              Accordion


              When you instantiate a navigator container, Flex creates all of the top-level children. For example, creating an ViewStack container triggers the creation of each of its views, but not the controls within those views. The creationPolicy property determines the creation of the child controls inside each view.

              When you set the creationPolicy property to auto (the default value), navigator containers instantiate only the controls and their children that appear in the initial view.

               

              When the user navigates to another panel in the Accordion container, the navigator container creates the next set of controls, and recursively creates the new view's controls and their descendants. You can use the ViewStack container's creationPolicy property to modify this behavior.

               

              The possible varlues for creationPolicy are  all, auto(default), none and queued.

               

              Thanks,

              Bhasker

              • 4. Re: how flex will create instances for components ?
                flex4 Level 2

                Hi BhaskarChari,

                 

                 

                 

                               Thanks for ur quick reply.. and thank u for explanation

                • 5. Re: how flex will create instances for components ?
                  fleRavix

                  Hi,

                  Flex will not create the 100 checkboxes at a time. When u r using an ItemRenderer, the checkboxes will be created at runtime.

                  For example, u have 100 chkboxes, in your runtime flex will display 20 records initially (means 20 chkBoxes), and if you scroll down, flex will then create the next 20 checkboxes. This is a very good feature in FLex IDE.

                   

                   

                  mark this if helpful

                  1 person found this helpful
                  • 6. Re: how flex will create instances for components ?
                    flex4 Level 2

                    Hi FleRavix,

                     

                     

                                 what is the correct answer?? Bhaskar told that in datagrid flex creates 100 check box instances for 100 records ... but u told that only 20 instances will create??

                     

                          what is the correct answer?? can any one refer the tutorial revealing this problem?

                     

                     

                                    I will go through that tutorial...    I am little bit confusion

                    • 7. Re: how flex will create instances for components ?
                      fleRavix Level 2

                      See,

                      When u r using itemrenderer, flex will not create the 100 chkBoxes at a time. Checkboxes will be rendered for the first 20 records in the grid. Wneh u scroll down, then next 20 will be rendered. This is correct and i have tested this.

                      not only chkboxes, anything in itemrenderers, will be created at runtime only.

                       

                      When your not using ItemRenderers, I agree flex will create the 100 chkboxes at a time.

                      1 person found this helpful
                      • 8. Re: how flex will create instances for components ?
                        BhaskerChari Level 4

                        @Flex4,

                         

                        Sorry I was wrong with my earliar post with itemrenderers...actually if you have 20 items or rows visible in a DataGrid Flex will create 22 itemRenderers—enough to show every visible row, plus a couple for buffering and performance reasons.

                         

                        And when the user scrolls the list, it may now be showing different rows. But those same 22 itemRenderers are still there: no new itemRenderers are created, even after the list scrolls. So what the Flex does is unless you resize the list, those same itemRenderers are reused and recycled to a new location and are now showing new data.

                         

                        However as I said in my previous post if you use Repeater component instead of itemRenderers all the 100 check boxes will be created..

                         

                        I have gone through the tutorial...its very useful and worthy indeed..Check out this link...you will get the most out of the Tutorial...

                         

                        http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html

                         

                        Thanks ,

                        Bhasker Chari