Hello,
I need a little help with asynchronous events in ActionScript 3. I am writing a simple class that has two functions, both of which return strings(logic and code outlined below). Due to the asynchronous nature of the AS3 HTTPService, the return value line is always reached before a result is returned from the service, yielding an empty string. Is it possible to include some type of logic or statement in this function that will make it wait for a response before returning a value? Is there a framework that handles this type of stuff?
- Call service
- Parse JSON result, isolate value of interest
Return Value
public function geocodeLocation(address:String):Point { //call Google Maps API Geocode service directly over HTTP var httpService:HTTPService = new HTTPService; httpService.useProxy = false; httpService.url = //"URL WILL GO HERE"; httpService.method = HTTPRequestMessage.GET_METHOD; var asyncToken : AsyncToken = httpService.send(); asyncToken.addResponder( new AsyncResponder( onResult, onFault));
}function onResult( e : ResultEvent, token : Object = null ) : void { //parse JSON and get value, logic not implemented yet var jsonValue:String="" } function onFault( info : Object, token : Object = null ) : void { Alert.show(info.toString()); } return jsonValue; //line reached before onResult fires