DataGrid 颜色背景的控制 Actionscript3版本(三)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="DataGrid_textAlign_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        initialize="init();">

<mx:Script>
        <![CDATA[
         import mx.controls.dataGridClasses.DataGridHeader;
            import mx.utils.ObjectUtil;
            import mx.controls.Alert;
            import mx.controls.DataGrid;
            import mx.controls.dataGridClasses.DataGridColumn;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;
            import mx.rpc.xml.SimpleXMLEncoder;
            import mx.utils.ObjectUtil;

            private var dataGrid:DataGrid;
            private var httpServ:HTTPService;
         
         
            private function init():void {
 
                httpServ = new HTTPService();
                httpServ.url = "airlines.xml";
                httpServ.resultFormat = "e4x";
                httpServ.addEventListener(ResultEvent.RESULT, httpServ_result);
                httpServ.addEventListener(FaultEvent.FAULT, httpServ_fault);
                httpServ.send();
 
            }

            private function httpServ_result(evt:ResultEvent):void {
             var x:XML=XML(httpServ.lastResult);
              var cols:Array = [];
              var dataGridCol1:DataGridColumn;
             for each(var y:XML in x.item){
              
              var xmllist:XMLList=y.children();
              
              //get element name and generate datagrid column dynamiclly
           
              for each(var z:XML in xmllist){
               
               var n:String = z.name().toString();
                dataGridCol1 = new DataGridColumn(n);
                dataGridCol1.itemRenderer = new ClassFactory(BackgroundComp);
                cols.push(dataGridCol1);
              }
              break;
              
             }             
                dataGrid = new DataGrid();
                dataGrid.columns = cols;
                addChild(dataGrid);
                dataGrid.dataProvider = XML(httpServ.lastResult).item;
            }

            private function httpServ_fault(evt:FaultEvent):void {
                Alert.show("Failed to load: " + evt.currentTarget.url, evt.fault.faultString);
            }
           
        ]]>
    </mx:Script>
</mx:Application>

你可能感兴趣的:(xml)