1 Reply Latest reply on Apr 28, 2011 12:54 PM by drkstr_1

    Trying to store unique data in each itemRenderer



      I have an itemRenderer with a dropDownList within, and I'm trying to set up these dropDownLists with unique dataProviders, as in each DropDownList will have a dataProvidier that is different from the next instance of the same itemRenderer.


      This dataProvider is stored in a private variable in the actionscript for my custom itemRenderer, and binded to the DropDownList. As it is now, if I assign a dataProvider to one dropDownList in the first instance of the itemRenderer and following this assign a second dataProvider to the dropDownList the second instance of the itemRenderer, the first instance of the itemRenderer will also reassign its DropDownlist's dataProvider.


      Basically I want this private variable to be able to contain unique data from the next instance of the itemRenderer. Is this possible?




        • 1. Re: Trying to store unique data in each itemRenderer
          drkstr_1 Level 4

          Item renderers are recylced, so you cannot rely on any internal data state, meaning that any given renderer may be used to display any given data item at any time.


          You need to store any persistant data in the underlying data item, not the renderer instance.



          Bad item renderer:


          private var _foo:String;
          private function doStuff():void
            _foo = "This will end badly";


          Good item renderer:


          private function doStuff():void
            this.data.foo = "Now I can attribute data to a specific item in the list...";





          After re reading your question, I also wanted to add that one possible solution is to create a linked list to reference the next item. Something like the following aught to do the trick:



          var lastItem:object;
          for each(var item:Object in myDataProvider)
                    lastItem.nextItem = item;
               item.lastItem = lastItem;
               lastItem = item;