Summary:How to load Data From XML File to DataGrid Component using action Script
First we need xml file at the root directory of the Application.So I created one like below .
First we need xml file at the root directory of the Application.So I created one like below .
<users> <user name="kirtan" password="123234"/> <user name="hiren" password="asdsad"/> <user name="Ghanshyam" password="75411"/> <user name="kirtan" password="123234"/> <user name="kirtan" password="123234"/> </users>And here is code how to display it in DataGrid. I named my DataGrid Component "dgv".
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import fl.data.DataProvider;
import fl.controls.dataGridClasses.DataGridColumn;
var req:URLRequest = new URLRequest("test.xml");
var loader:URLLoader = new URLLoader(req);
var xmlData:XML;
loader.addEventListener(Event.COMPLETE,onListenerCompleted)
function onListenerCompleted(e:Event)
{
xmlData = new XML(e.target.data);
var dp:DataProvider = new DataProvider(xmlData);
var col1:DataGridColumn = new DataGridColumn("name");
col1.headerText = "Username";
col1.width = 200;
var col2:DataGridColumn = new DataGridColumn("password");
col2.headerText = "Password";
col2.width = 200;
dgv.columns = [col1,col2];
dgv.width = 400;
dgv.dataProvider = dp;
dgv.rowCount = dgv.length;
}
![]() |
| Load XML Data in DataGrid using Action Script |

No comments:
Post a Comment