Flexcomps’s Weblog

AS3 XML Loader Utility Class

Posted by: Yogesh Puri on: September 23, 2008

I have developed this XMLUtility class in conjunction with a CustomEvent Class which returns me the loaded XML/String Data along with the complete event firing. You can download the sources from here. Following is the code you need to write when you want to load this class


//------------ Import Classes
import com.flexcomps.utils.CustomEvent;
import com.flexcomps.utils.XMLLoaderUtil;


//-------- Create instance of loader class
var xmlLoader:XMLLoaderUtil = new XMLLoaderUtil();
xmlLoader.addEventListener(CustomEvent.ONLOADED, onXMLLoaded);
xmlLoader.load(xmlPath);


//----- Method to handle the returned data
private function onXMLLoaded(evt:CustomEvent) {
xmlData = evt.data as XML;
trace(xmlData);
}

3 Responses to "AS3 XML Loader Utility Class"

Nice one. Even though it’s handy is there much benefit to using this over existing classes? ie.

var xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
xmlLoader.load(new URLRequest(xmlPath));

private function onXMLLoaded(evt:Event) {
xmlData = XML(xmlLoader.data.toString());
}

The benefit is in terms of object disposing which has been handled by class itself and secondly if you want to change the event when you want to fetch data, it becomes a central place to modify. :)

[...] Visit link: AS3 XML Loader Utility Class [...]

Leave a Reply

 

September 2008
M T W T F S S
« Aug   Oct »
1234567
891011121314
15161718192021
22232425262728
2930  

Blog Stats

  • 94,229 hits