4 Replies Latest reply on Mar 9, 2012 11:03 AM by Claudiu Ursica

    Passing additional data to an ItemRenderer


      Hello, here is the scene:


      Using Flash Builder 4, SDK 4.1;

      An s:List that displays products by category;

      The List's dataProvider is an ArrayCollection of products;

      An ItemRenderer - a DataRenderer - shows each product; this renderer has several States.


      The renderer changes state based on the number of products in the category being displayed.


      I need to pass the ArrayCollection's length to the DataRenderer so it knows what state to use.


      If anyone has any ideas about this, I would love to hear.





        • 1. Re: Passing additional data to an ItemRenderer
          cheftmo Level 1

          peterent was the guru of ItemRenderers, but I haven't seen his posts recently. Anybody know if he's still with Adobe?


          So, where are you, flexHarUI, Gregory Lafrance? This question seems like right up your alley.


          Nobody wants to take a shot at this?





          • 2. Re: Passing additional data to an ItemRenderer
            saisri2k2 Level 4

            I would use a singleton or a static variable to hold the lenght of the arraycollection. since they are available evry where, I can access it in the renderer in the set data method and decide what to show.





            List.dataProvider = arrayCollection

            StaticPublicVarialbeOfThisClass = arrayCollection.length




            in the DataRenderer


            set data(value:Object):


                 currentState = ThatClass.StaticPublicVarialbeOfThisClass  == 10 ? "10state":"noneState";




            1 person found this helpful
            • 3. Re: Passing additional data to an ItemRenderer
              cheftmo Level 1

              Hello again:


              I think saisri2k2's suggestion has put me on the right track, although working on this for the past couple of days has not solved the problem.


              If anyone wants to look at this, the project is here, http://www.timos.com/LeCreuset/LeCreuset.html and View Source is enabled. The file you want to look at is src > renderers > ProductThumb.mxml.


              If you are looking at source, know that I have tried the following:


              • the variable ‘filterCount’ as public static;
              • the function ‘showsSalePrice()’ inside the get data getter instead of on the dataChange event;
              • invalidateProperties() in various places.


              None of the above has worked: the filterCount is correct when you select a new category. When you select a category with fewer than 16 products, the tiles change to a state where they are bigger (as they should). But once they have turned bigger, they don not want to return to a state where they should be smaller when you switch to a category with more products. If you try changing categories using the ComboBox you will see this.


              So I don’t know what else to try. I have a hunch this may have something to do with the fact that the renderers are recycled when the containing list uses the virtualization (which apparently you can’t turn of in an s:List).


              If anyone has any ideas/suggestions, I would love to hear them.


              Thanks and greeting to y’all,



              • 4. Re: Passing additional data to an ItemRenderer
                Claudiu Ursica Level 4

                Actually it is quite straightforward you just have to "ask the owner" about the length. I posted a small example on my blog have a look:

                http://blog.claudiu-ursica.ro/2012/03/08/updating-an-itemrenderer-style-or-state-based-on- the-parent-list-based-controls-number-of-items/