Copy link to clipboard
Copied
I am trying to read from an xml file which contains flight info and want to display them in a datagrid or a table in AS3, but I can't manage to do that. Can someone point me to the right direction. Thank you in advance.
Copy link to clipboard
Copied
This help file has an example: Adobe ActionScript 3.0 * Use the DataGrid component
Copy link to clipboard
Copied
use the urlloader class to load your xml file.
if that's a cross-domain xml file and you can't add a policy file to the xml hosting server, using a php gateway is a good work-around.
Copy link to clipboard
Copied
Thank you for your answer. I've done an example but I have a problem with it the dataProvider only reads 2 tags in the xml file and adds it in the DataGrid. here is the xml file.
<?xml version="1.0" encoding="ISO-8859-1"?>
<airlines>
<flightdescription>
<id> 1 </id>
<flightno> usa1000 </flightno>
<origin>Chicago</origin>
<destination>Boston</destination>
<departurdatetime>2015/03/29 14:45 </departurdatetime>
<arrivaldatetime>2015/03/30 23:45</arrivaldatetime>
<img src='C:\Users\sherif\Desktop\Fujitsu - Digital media solution\Flash\US-Airways-Logo'/>
</flightdescription>
</airlines>
I've shortened the xml file.
and this is the as3 code:
var myDataGrid:DataGrid = new DataGrid();
myDataGrid1.addColumn("flight no");
myDataGrid1.addColumn("origin");
myDataGrid1.addColumn("destination");
myDataGrid1.addColumn("departure date & time");
myDataGrid1.addColumn("arrival date & time");
var dp:DataProvider;
var urlAirlines:String = "airlines.xml";
var reqAirlines:URLRequest = new URLRequest(urlAirlines);
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, AirlinesHandler);
urlLoader.load(reqAirlines);
function AirlinesHandler(event:Event):void {
var xmlDP:XML = new XML(urlLoader.data);
dp = new DataProvider(xmlDP);
myDataGrid1.dataProvider = dp;
//myDataGrid1.columnCount = mydataGrid1.width;
myDataGrid1.rowCount = myDataGrid1.length+2;
myDataGrid1.columns[0].width = 70;
myDataGrid1.columns[1].width = 70;
myDataGrid1.columns[2].width = 90;
myDataGrid1.columns[3].width = 130;
myDataGrid1.columns[4].width = 130;
myDataGrid1.horizontalScrollPolicy = ScrollPolicy.ON;
trace(dp);
trace(myDataGrid1);
}
the output only reads the tags Origin and Destination and adds them in DataGrid. anyone have any ideas?? Thank you in advance.
Copy link to clipboard
Copied
your column names should match the xml tag names (even down to the typos).
Copy link to clipboard
Copied
Thank you very much for your reply. I have one more question there is an image tag in my xml can I add it to my dataGrid??
Copy link to clipboard
Copied
you'll need to use a custom cellrenderer.
google a tutorial for an as3 custom cellrenderer datagrid.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now