AS2 → AS3: Load An XML File
Loading XML in AS3 requires the use of the new Event system. In AS2 you could just tell the XML object to perform a method onLoad (when the XML file has finished loading and is ready to be parsed). In AS3 you have to add a listener to the Event.COMPLETE event and call your function to parse the XML after that event is fired off.
Here is the AS2 code:
Actionscript:
-
var XML:XML = new XML();
-
XML.ignoreWhite = true;
-
XML.onLoad = traceComplete;
-
XML.load("data.xml");
-
-
function traceComplete():Void
-
{
-
trace("XML LOADED!");
-
}
And here is the AS3 version:
Actionscript:
-
var xmlURL:String = "data.xml";
-
var xmlLoader:URLLoader = new URLLoader();
-
-
xmlLoader.addEventListener(Event.COMPLETE, traceComplete);
-
xmlLoader.load(new URLRequest(xmlURL));
-
-
function traceComplete($e:Event):void
-
{
-
trace("XML LOADED!");
-
}
If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.











No Comments
No comments yet.
Leave a comment