
ActionScript 3 uses a system called ECMAScript for XML (E4X).
In AS2 we were used to create an XML object and then we called the XML.load() method in order to load in an external file. In AS3 loading of external XML files is handled by the new URLLoader class.
So, let’s create a new instance of that class:
Actionscript 3 code
var loader:URLLoader=new URLLoader;
After that we need to create an event to launch the function when the XML is loaded. The event must be deleted before deleting the object, otherwise it will sucks CPU
Actionscript 3 code
loader.addEventListener(Event.COMPLETE, loadXML);
Let’s give the loader the target XML to load:
Actionscript 3 code
loader.load(new URLRequest("content.xml"));
Finally, let’s create the function to load the content using the Event.target.data property:
Actionscript 3 code
function loadXML(e:Event):void
{
xml = new XML(e.target.data);
trace(xml);
}