/ Published in: ActionScript 3
Simple usage:
var xmlLoader:LoadXMLUtil = new LoadXMLUtil("path_to_xml.xml");
xmlLoader.addEventListener(Event.COMPLETE, onLoaderComplete);
private function onLoaderComplete(event:Event):void{
trace("Loaded XML: ");
trace(xmlLoader.xml);
}
var xmlLoader:LoadXMLUtil = new LoadXMLUtil("path_to_xml.xml");
xmlLoader.addEventListener(Event.COMPLETE, onLoaderComplete);
private function onLoaderComplete(event:Event):void{
trace("Loaded XML: ");
trace(xmlLoader.xml);
}
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package utils { /* Author: Bassta Simple XML Loadig util - takes on parameter in the constructur function; path_to_xml is String, which tells where the xml file is Dispatches Event.COMPLETE when the xml is loaded you can retrive the XML by using "xml" getter function */ import flash.events.*; import flash.net.*; public class LoadXMLUtil extends EventDispatcher{ private var _source:XML; private var loader:URLLoader = new URLLoader(); public function LoadXMLUtil(path_to_xml:String){ loader.addEventListener(Event.COMPLETE, onComplete, false, 0, true); loader.load(new URLRequest(path_to_xml)); } internal function onComplete(event:Event):void{ loader.removeEventListener(Event.COMPLETE, onComplete); XML.ignoreWhitespace = true; _source = new XML(event.target.data); dispatchEvent(event.clone()); } public function get xml():XML{ return _source; } }//end }