XMLLoader 2.0 « Cleck Here
Even though with AS 3.0, dealing with XML has became very easy. I still don't like writing this...
var myXML:XML = new XML();
var myLoader:URLLoader = new URLLoader();
var myURL:URLRequest = new URLRequest("titles.xml");
myLoader.addEventListener(Event.COMPLETE, loadXML);
myLoader.load(myURL);
function loadXML(e:Event) {
myXML = new XML(e.target.data);
return myXML;
Having to create URLLoaders, URLRequests and set up Event Listeners becomes time consuming and annoying when you are loading from more than one XML file. So I decided to create a class to quickly load up XML. This class is simple and easy to use.
You simply create an instance of the class with 2 parameters. The first being your XML file and the second (which is optional) a function you want executed when the XML is done loading. Yup that is right, you don't even have to set up listeners. All the information is then stored in the nodes property. Here is an example of the code.
import com.clementegomez.utils.XMLLoader;
var myLoader:XMLLoader = new XMLLoader("myXML.xml",
doSomething);
function doSomething(e:Event){
trace(myXML.nodes);
And thats all to it. This class doesn't require any 3rd Party classes to run. There are still some things I would like to implement but it does get the job done fast and easy so far. If you like the class or have any ideas or functions to add, leave a comment and let me know. Hope this is as useful to you as it is to me.
Download Here XMLLoaderClass
No comments:
Post a Comment