Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Reading from an xml and adding data to a datagrid AS3

New Here ,
Jan 05, 2015 Jan 05, 2015

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.

TOPICS
ActionScript
389
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 06, 2015 Jan 06, 2015
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2015 Jan 06, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 11, 2015 Jan 11, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2015 Jan 11, 2015

your column names should match the xml tag names (even down to the typos).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 14, 2015 Jan 14, 2015

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??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2015 Jan 14, 2015
LATEST

you'll need to use a custom cellrenderer.

google a tutorial for an as3 custom cellrenderer datagrid.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines