主文件中关键代码如下:
var Arr:Array=new Array(); for (var i:int=0; i<JobListXML.length(); i++) { Arr.push({data:"images/ie.jpg", "Job No.":JobListXML[i].@JobNo, "Address":JobListXML[i].@Address, rowColor:String(JobListXML[i].@ArrangedColor) }); } DG.dataProvider = new DataProvider(Arr); DG.setStyle("cellRenderer", CellStyle1);
CellStyle1.as
/*本类的功能: 1.设置表格的颜色交替显示,前提是要在datagrid皮肤里新增mc.操作如下: 库中 Component Assets/CellRendererSkins 下,将CellRenderer_upSkin复制一份,命名为CellRenderer_upSkinGray,并将其颜色改为自己需要的 2.设置指定行的颜色显示 */ package { import fl.controls.listClasses.CellRenderer; import fl.controls.listClasses.ICellRenderer; import flash.text.TextFormat; public class CellStyle1 extends CellRenderer implements ICellRenderer { public function CellStyle1():void { super(); } override protected function drawBackground():void { var format:TextFormat = new TextFormat(); switch (data.rowColor) { case "green" : format.color=0x00FF33; format.size=24; format.align = "center"; //其他属性自己设; setStyle("textFormat",format); break; case "0xFF0000" : format.color=0xFF0000; format.size=12; // format.align = "center"; format.bold=true; //其他属性自己设; setStyle("textFormat",format); break; case "yellow" : format.color=0xFFFF00; format.size=12; format.align = "center"; setStyle("textFormat",format); break; default : break; } if (_listData.index % 2 == 0) { setStyle("upSkin", CellRenderer_upSkinGray); } else { setStyle("upSkin", CellRenderer_upSkin); } super.drawBackground(); } } }