3 Replies Latest reply on Feb 20, 2009 6:31 AM by MrFork

    itemRenderer listData value = null

    MrFork Level 1
      Please see my itemRenderer below. Im having issues pulling out the listData value so that I can reuse this itemRenderer across my advanced dataGrid. The listData variable is coming out as null. Then in the MXML Label instead of data.ATVIndex it should be data[listData], is this correct?

      Please help! I've been stuck on this for hours

      <?xml version="1.0" encoding="utf-8"?>
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%" height="100%">

      <mx:Script>
      <![CDATA[
      import mx.controls.advancedDataGridClasses.AdvancedDataGridListData
      import mx.controls.dataGridClasses.DataGridListData;
      import mx.controls.listClasses.BaseListData;
      import mx.core.UIComponent;
      import mx.controls.listClasses.IDropInListItemRenderer;

      // Internal Variable for the property value
      private var _listData:BaseListData;

      // Make the listData property binaable
      [Bindable("dataChange")]

      // Define the getter method
      public function get listData():BaseListData
      {
      return _listData;
      }

      // Define the setter method
      public function set listData( value:BaseListData ):void
      {
      _listData = value;
      }

      public function addImage(score:Object):String
      {
      trace (listData);
      if (score >1)
      {
      for(var __i:Number=0;__i<5;__i++){
      var ui:UIComponent = new UIComponent();
      if(__i < score){
      ui.graphics.beginFill(0x74be21,1);
      }else{
      ui.graphics.beginFill(0xFFFFFF,1);
      }
      ui.graphics.lineStyle(1,0x000000,1);
      ui.graphics.moveTo(__i*(7+2),6);
      ui.graphics.lineTo(7+(__i*(7+2)),6);
      ui.graphics.lineTo(7+(__i*(7+2)),13);
      ui.graphics.lineTo(__i*(7+2),13);
      ui.graphics.lineTo(__i*(7+2),6);
      scoreBox.addChild(ui);
      }
      return score.toString();

      }
      else
      {
      for(var __i:Number=0;__i<5;__i++){
      var ui:UIComponent = new UIComponent();
      if(__i < score){
      ui.graphics.beginFill(0xd14007,1);
      }else{
      ui.graphics.beginFill(0xFFFFFF,1);
      }
      ui.graphics.lineStyle(1,0x000000,1);
      ui.graphics.moveTo(__i*(7+2),6);
      ui.graphics.lineTo(7+(__i*(7+2)),6);
      ui.graphics.lineTo(7+(__i*(7+2)),13);
      ui.graphics.lineTo(__i*(7+2),13);
      ui.graphics.lineTo(__i*(7+2),6);
      scoreBox.addChild(ui);

      }
      return score.toString();
      }
      }
      ]]>
      </mx:Script>
      <mx:Label id="myLabel" text="{addImage(data.ATVIndex)}"/>
      <mx:HBox id="scoreBox" height="100%" horizontalGap="0"/>
      </mx:HBox>
        • 1. Re: itemRenderer listData value = null
          Level 7
          addImage is getting called right away, before the listData has been set.
          What you want to do is to do everything that you're doing in addImage in
          updateDisplayList instead. Then have changing the data or the listData
          invalidate the display list, and check to make sure that they're both
          set before you execute the commands (since you seem to be using both).
          • 2. Re: itemRenderer listData value = null
            Level 7

            "Nate Skiba" <nate.skiba@gmail.com> wrote in message
            news:gnm6qg$1up$1@forums.macromedia.com...
            > addImage is getting called right away, before the listData has been set.
            > What you want to do is to do everything that you're doing in addImage in
            > updateDisplayList instead. Then have changing the data or the listData
            > invalidate the display list, and check to make sure that they're both
            > set before you execute the commands (since you seem to be using both).

            Also make sure you're telling Flex that it's allowed to set listData on your
            component.

            <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%"
            height="100%" implements="IDropInListItemRenderer">

            Note that you may need to use the fully qualified path instead of just
            IDropInListItemRenderer, but I'd rather you looked that info up than me.


            • 3. Re: itemRenderer listData value = null
              MrFork Level 1
              implements fixed the issue - THANKS AMY!! I love you :)