8 Replies Latest reply on May 9, 2009 5:45 PM by Michael Borbor

    Item renderers re-rendering on window resize

    RS-VN

      Hi all,

       

      I'm having an issue with my custom item renderers. Basically I've got the following:

       

      MXML file one has a datagrid with three columns.

       

      The data provider is an ArrayCollection with 3 entries each containing 3 datafields (ie. Time, Stats and Slots). Now the slots datafield is actually a reference to an alternate ArrayCollection. So the data provider of my datagrid is an ArrayCollection, which itself contains three additional arrays in this example. The slots uses an itemRenderer with a repeater inside to go through the array of 'Slots' and display them all in a single datagrid cell.

       

      Here is the code around the datagrid:

       

       

      <mx:DataGrid dataProvider="{anArray}"

      variableRowHeight="true"

      selectable="false"

      sortableColumns="false"

      width="100%">

      <mx:columns>

      <mx:DataGridColumn headerText="header1"

         width="50"

         dataField="Time">

      </mx:DataGridColumn>

      <mx:DataGridColumn headerText="header1"

         dataField="Slots"

         itemRenderer="someRenderer">

      </mx:DataGridColumn>

      <mx:DataGridColumn headerText="T header1"

         width="150"

         dataField="Stats">

      </mx:DataGridColumn>

      </mx:columns>

      </mx:DataGrid>

       

       

      And here is the code for part of the itemRenderer

       

       

      <mx:Tile xmlns:mx="http://www.adobe.com/2006/mxml"

      horizontalGap="4"

      verticalGap="4"

      paddingLeft="4"

      paddingBottom="4"

      paddingRight="4"

      paddingTop="4"

      verticalScrollPolicy="off"

      horizontalScrollPolicy="off">

      <mx:Script>

      <![CDATA[

       

      import mx.core.UIComponent;

      import mx.containers.VBox;

       

       

      private function handleRepeater() : void

      {

      var anItem: OtherItemMXML= new OtherItemMXML();

      var component : UIComponent = new UIComponent();

      anItem.referenceName = resRepeat.currentItem.Ref;

      anItem.value1 = resRepeat.currentItem.Value1;

      anItem.value2 = resRepeat.currentItem.Value2;

      anItem.value3 = resRepeat.currentItem.Value3;

      anItem.value4 = resRepeat.currentItem.Value4;

      component.addChild( anItem );

      component.visible = true;

      addChild( component );

      }

      ]]>

      </mx:Script>

       

      <mx:Repeater id="resRepeat"

      dataProvider="{data.Slots}"

      repeat="handleRepeater()">

      </mx:Repeater>

       

      <mx:VBox width="100"

      height="74"

      backgroundColor="#FFFFFF"

      verticalGap="0"

      verticalAlign="middle"

      mouseMove="dragInit(event)">

       

      </mx:VBox>

      </mx:Tile>

       

      So the end result of all this is that, when I first run the app, all my data in my SLOTS arrays are doubled.... meaning they all appear twice on the screen (ie. I've got one slots array with 3 items in it, well it shows up with 6 on screen).

       

      Second issue is that whenever I resize the screen (ie. Restore/Maximise), a new set of items get added to the grid, but this time, not doubled. So if I restore and maximize my screen, I end up with 4 times the initial number of items in my ArrayCollection...

       

      Any ideas why this might be happening?

       

      If you need more details let me know.

       

      Thanks!

       

      Marc