I have this static public function berechne()
and I want this function to return data
. But data
is inside another function, so I can't access it outside the function to return it. I also can't let the second function away, because it is necessary to receive the fetched data after Event.COMPLETE
.
How can I return data
?
berechne():
static public function berechne(value1: String): Object {
var request: URLRequest = new URLRequest('http://localhost/whatever.json');
var loader: URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, responseReceived);
loader.load(request);
function responseReceived(event: Event): void {
var data:Object = JSON.parse(loader.data); //I would like to return this ...
}
return data; //... here
}
Thank you!
You can try this setup:
Another way is to just avoid the Return part and instead use the function to update your Object directly (as a function parameter).
In this example,
Your Object that should be updated by a return is now passed in as a parameter
value2
: