Revision: 41709
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at February 22, 2011 22:13 by burnandbass
Initial Code
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
}
Initial URL
Initial Description
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);
}
Initial Title
Easy XML Loading util
Initial Tags
xml
Initial Language
ActionScript 3