toppi
11-17-2009, 07:30 AM
I have this PhotoService class that is supposed to fetch a XML page (given by an argument) and return a XMLList. I've declared a XMLList-typed static variable but for some reason I can't return it. Please help me understand how come it won't work.
Here's a snippet of the class:
public class PhotoService {
private static var results:XMLList;
public function PhotoService(source:String) {
var url:URLLoader = new URLLoader(new URLRequest(source));
url.addEventListener(Event.COMPLETE, handleXML);
}
private function handleXML(e:Event):XMLList {
var temp:XML = new XML(e.currentTarget.data);
results = new XMLList(temp.img); // img as in xml
trace(results); // this works
return results; // but it returns null somehow
}
}
Here's a snippet of the class:
public class PhotoService {
private static var results:XMLList;
public function PhotoService(source:String) {
var url:URLLoader = new URLLoader(new URLRequest(source));
url.addEventListener(Event.COMPLETE, handleXML);
}
private function handleXML(e:Event):XMLList {
var temp:XML = new XML(e.currentTarget.data);
results = new XMLList(temp.img); // img as in xml
trace(results); // this works
return results; // but it returns null somehow
}
}