package bontos
{
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
/**
* Load XML and call function named in 2 parameter:
* url - for XML file
* call back function - called on complete loaded xml file
*
* Default url = "images.xml"
*
* */
public class ReaderXML
{
public var xmlObj: XML = new XML();
private var urlForDefaultXML: String = "images.xml";
private var myLoader: URLLoader;
private var callBackFunction: Function;
public function ReaderXML(aUrl: String, callBackFunc: Function)
{
aUrl = (!aUrl || aUrl == 'null' || aUrl.length < 5) ? urlForDefaultXML : aUrl;
callBackFunction = callBackFunc;
var myXMLURL:URLRequest = new URLRequest(aUrl);
try{
myLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
}catch(e:Error){}
}
private function xmlLoaded(event:Event):void{
xmlObj = XML(myLoader.data);
trace('xml loaded');
if(callBackFunction != null) {
callBackFunction(xmlObj);
}
}
private function onError(event:IOErrorEvent):void{
trace(' IO_ERROR xml == ', event.text);
}
}
}