1 Reply Latest reply on Apr 29, 2010 9:54 AM by Flex harUI

    ItemRenderer DataGrid

    play();

      Hi,

       

      I am having problems with ItemRenderer recycling and/or re-instantiation.

       

      I have a DataGrid, and 1 of the pieces of data i need to show (a timestamp in this case) is updated every 5000 millis).

       

      The problem i am having is that when i get new data in - the first ItemRenderer is re-instantiated and the rest are recycled. Data is therefore moved around.  I understand why this happens (the flex architecture), but i think i have done all i can to make my ItemRenderer Data-driven.

       

      The ItemRenderer looks like this:

       

      package
      {
           import flash.display.MovieClip;
           import flash.events.MouseEvent;
          
           import mx.binding.utils.BindingUtils;
           import mx.binding.utils.ChangeWatcher;
           import mx.controls.DataGrid;
           import mx.controls.dataGridClasses.DataGridListData;
           import mx.controls.listClasses.BaseListData;
           import mx.controls.listClasses.IDropInListItemRenderer;
           import mx.controls.listClasses.IListItemRenderer;
           import mx.core.IDataRenderer;
           import mx.core.UIComponent;
           import mx.events.FlexEvent;
          
           public class LobbyStartTimeSkin extends UIComponent implements IDataRenderer,
                                                                           IListItemRenderer,
                                                                           IDropInListItemRenderer
           {
               [Embed(skinClass="lobbyStartTime")]
               private var lobbyStartTime:Class;
              
               private  var sym:MovieClip;
               private var _changeWatcher:ChangeWatcher;
              
                private var _data:Object;
               
               public function LobbyStartTimeSkin()
               {
                   super();
               }
              
               override protected function createChildren():void
               {
                   super.createChildren();
                  
                   var box:MovieClip = new MovieClip();
                  
                   sym = new lobbyStartTime() as MovieClip;
                   sym.x = 30;
                   sym.y = 25;
                  
                   addChild(sym) as MovieClip;
               }
              
               override protected function measure():void
               {   
                   super.measure();
                  
                   measuredWidth = 70;
                   measuredHeight = 50;          
               }
              
               private var _listData:BaseListData;
               
               public function get listData():BaseListData
               {
                   return _listData;
               }
              
               public function set listData(value:BaseListData):void
               {
                   _listData = value;
               }
              
               // IDataRenderer
               public function get data():Object
               {
                   return _data;
               }
                
               public function set data(value:Object):void
               {
                    if(value != null)
                   {
                       if (_changeWatcher!=null)
                       {
                           _changeWatcher.reset(value);
                          
                       }
                       else
                       {
                           _data = value;
                           _changeWatcher = BindingUtils.bindSetter(setStrStartTime,value,"strTimeLeft");
                       }
                   }
              
                   //invalidateProperties();
                  
                   //dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
                  
                  //invalidateDisplayList();
               }
              
               public function setStrStartTime(value:String):void
               {
                   if(sym.label.text != null && value != null)
                   {
                       sym.label.text = value;               
                   }
               }
                      
               override protected function updateDisplayList(unscaledWidth:Number,  unscaledHeight:Number):void
               {
                   super.updateDisplayList(unscaledWidth, unscaledHeight);
                  
                   var grid:DataGrid = DataGrid(DataGridListData(listData).owner);
                  
                   if (grid.isItemSelected(data) || grid.isItemHighlighted(data))
                   {
                       return;
                   }

       

                  sym.setActualSize(50,40);

       

                  if(listData.rowIndex == 0)
                   {
                       sym.move(30,25);
                   }
                   else
                   {
                       sym.move(30, 29);
                   }
               }
           }
      }

       

      How can i keep the data in the correct row positions?

       

      Regards, play()