1 Reply Latest reply on Aug 14, 2009 3:48 AM by Madhav Subedi

    Help needed to add an image to a datagrid cell in actionscript

    xandesign Level 1

      Morning all,


      I am still quite new to flex development and I have an application which uses xml to populate a datagrid. One of the row columns should display a small image but I don't know how to do that.


      Can anyone show me how to add an image to a datagrid cell in actionscript?


      I've added a sample of the code I have written already below. Any help would be much appreciated.


      Thanks in advance,





      My XM

      <?xml version="1.0" encoding="UTF-8"?>
      <module id="1">
      <description>Description of module</description>
      <installed>Wednesday, 24th June 2009 @ 15:59 UK</installed>
      <module id="2">
      <name>Web Project</name>
      <description>Description of module</description>
      <installed>Wednesday, 24th June 2009 @ 17:32 UK</installed>



      My Actionscript

      private function dataSetHandler(event:Event):void {
          var ds:XML = new XML(event.target.data);
          var rows:XMLList = ds.elements('modules').elements('module') as XMLList;
          var columns:Array = new Array();
          for (var i:int=0; i<rows[0].elements().length(); i++) {
              var column:DataGridColumn = new DataGridColumn();
              var tag:String = rows.*[i].name();


              column.headerText = rows.*[i].name();

              column.dataField = rows.*[i].name();
              if (tag == 'icon') {
                  var img:Image = new Image();
                  img.id = "iconpath";
                  img.width = 23;
                  img.height = 20;
                  img.source = rows.*[i].name();
                 column.itemRenderer = img;   <-- this line shows as an error when I try to compile
              columns[i] = column;
          mydatagrid.columns = columns;
          mydatagrid.dataProvider = rows;