PDA

View Full Version : problem when returning a value


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
}
}

kunjan
11-17-2009, 09:39 AM
Hello toppi,

You have specify return type xmllist and result has no any type so make rerun type string and declare result as a string it can solve your problem.

Regards,
Kunjan.