First off i feel like i shouldnt have to import flash.events.Event or flash.events.IOErrorEvent because shouldnt those be apart of URLLoader? I get an error if i dont include them both. Second when I instantiate var song:Songs = new Songs(file.xml); it never gets inside the onComplete function or the onIOError. I tried hard coding the xml file name into the loader but it still didnt go into the onComplete function. Any thoughts?
package {
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
public class Songs{
var track:Number;
var songXML:XML;
var songList:XMLList;
var loader:URLLoader = new URLLoader();
public function Songs(file){
loader.addEventListener( Event.COMPLETE, onComplete,false, 0,true);
loader.addEventListener( IOErrorEvent.IO_ERROR, onIOError, false, 0, true);
loader.load( new URLRequest(file));
}
private function onComplete(evt:Event):void {
try{
songXML = new XML(evt.target.data);
songList = songXML.song;
trace(songList);
loader.removeEventListener(Event.COMPLETE, onComplete);
loader.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
}catch(err:Error){
trace("problem");
}
}
private function onIOError(evt:IOErrorEvent):void{
trace("Error");
}
}
}