datagrid加载xml数据的as代码

// ActionScript file
package com.test.datagrid
{
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;

import mx.controls.Alert;
import mx.controls.DataGrid;

public class DataGrid_ShowData_Example
{
private var data_xml:XML;
private var myXMLURL:URLRequest;
private var myLoader:URLLoader;


private var results:XMLList;

/*****************************************
* 构造函数
* */
public function DataGrid_ShowData_Example()
{
GetData1();
}

/*********************************
* 加载内部数据,绑定DataGrid组件
* */
private function GetData1():void
{
// 加载外部XML文件
data_xml = new XML();
myXMLURL = new URLRequest("data.xml");
myLoader = new URLLoader(myXMLURL);

myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}

/*********************************
* 绑定DataGrid组件
* */
private function xmlLoaded(event:Event):void
{
data_xml = XML(myLoader.data);
//trace(data_xml.elements("node").toXMLString());

results=data_xml.children();     //结果集传递给results变量

Alert.show("results = " +  results);
}

public function getData():XMLList{
return results;
}
}
}

你可能感兴趣的:(datagrid)