The XML:
<root>
   <item>
       <name value="Pete" type="1" />
       <city value="NY" type="2" />
       <phone value="33-22-555" type="1" />
       <count value="10" type="1" />
   </item>
   <item>
       <name value="Pete2" type="2" />
       <city value="NY" type="1" />
       <phone value="33-22-555" type="1" />
       <count value="10" type="3" />
   </item>
   <item>
       <name value="Pete3" type="1" />
       <city value="NY" type="1" />
       <phone value="33-22-555" type="1" />
       <count value="10" type="1" />
   </item>
</root>


The CODE:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute"
   creationComplete="init();dgRPC.send()">
   <mx:Script>
       <![CDATA[
           import components.CellColorer;
           import vo.DGCellContainer;
           import mx.collections.ArrayCollection;
           import mx.rpc.events.ResultEvent;

           [Bindable]
           private var dgData:ArrayCollection=new ArrayCollection();

           private var aColors:Array=new
Array('','0xff0000','0x00ff00','0x0000ff');

           private function init():void
           {

               var nameCellColorer:ClassFactory=new
ClassFactory(CellColorer);
               nameCellColorer.properties={bShowName:true};
               colName.itemRenderer=nameCellColorer;

               var cityCellColorer:ClassFactory=new
ClassFactory(CellColorer);
               cityCellColorer.properties={bShowCity:true};
               colCity.itemRenderer=cityCellColorer;

           }

           private function onDataGridResult(event:ResultEvent):void
           {
               var dgc:DGCellContainer;
               trace("!")
               for each(var p:XML in event.result..item)
               {
                   dgc=new DGCellContainer();
                   [EMAIL PROTECTED];
                   dgc.nameColor=aColors[Number([EMAIL PROTECTED])];
                   [EMAIL PROTECTED];
                   dgc.cityColor=aColors[Number([EMAIL PROTECTED])];
                   [EMAIL PROTECTED];
                   dgc.phoneColor=aColors[Number([EMAIL PROTECTED])];
                   [EMAIL PROTECTED];
                   dgc.countColor=aColors[Number([EMAIL PROTECTED])];
                   dgData.addItem(dgc);
               }
           }
       ]]>
   </mx:Script>

   <mx:HTTPService url="stub/ColoredDataGrid.xml" id="dgRPC"
result="onDataGridResult(event)" resultFormat="e4x"/>
   <mx:DataGrid x="0" y="0" width="378" height="192"
dataProvider="{dgData}" headerColors="{[0xff0000]}">
       <mx:columns>
           <mx:DataGridColumn id="colName" headerText="Name"
dataField="name"/>
           <mx:DataGridColumn id="colCity" headerText="City"
dataField="city"/>
           <mx:DataGridColumn headerText="Phone" dataField="phone"/>
           <mx:DataGridColumn headerText="Count" dataField="count"/>
       </mx:columns>
   </mx:DataGrid>
</mx:Application>

Reply via email to