Load XML Files with Adobe Air
I am currently working on an Air2 application and had also work with XML. Last time I had the honor to fight with XML files I was using ActionScript 2 and Flash, so I was happy to switch to ActionScript 3. But like always, there is a small problem. Air2 handles XML a little bit different than Flash. So if you want to load a XML file you have the choice between a local or an online file. And here is the way to handle it:
- //Load LOCAL XML File:
- var XMLfile:File = File.applicationDirectory.resolvePath("XMLfile.xml");
- var myXMLLoader:URLLoader = new URLLoader(new URLRequest(XMLfile.url));
- myXMLLoader.addEventListener(Event.COMPLETE, xmlLoaded);
//Load LOCAL XML File:
var XMLfile:File = File.applicationDirectory.resolvePath("XMLfile.xml");
var myXMLLoader:URLLoader = new URLLoader(new URLRequest(XMLfile.url));
myXMLLoader.addEventListener(Event.COMPLETE, xmlLoaded);On a local file, it is important to include this file also in the project. This is posible by opening the project settings and add the xml file at “list of included files“.
- //Load Online XML File:
- var XMLURL:String = "http://domain.com/XMLfile.xml";
- var NewXML:URLRequest = new URLRequest(XMLURL);
- var myXMLLoader:URLLoader = new URLLoader(NewXML);
- myXMLLoader.addEventListener("complete", xmlLoaded);
//Load Online XML File:
var XMLURL:String = "http://domain.com/XMLfile.xml";
var NewXML:URLRequest = new URLRequest(XMLURL);
var myXMLLoader:URLLoader = new URLLoader(NewXML);
myXMLLoader.addEventListener("complete", xmlLoaded);You have questions?Ask them
Further Reading: ActionScript 3 XML Basics and Create Your Own Adobe AIR Application with Flash