我需要一些关于ActionScript 3中异步事件的帮助。我正在编写一个简单的类,它有两个函数,它们都返回字符串(逻辑和代码如下)。由于AS3 HTTPService的异步特性,在服务返回结果之前总是返回值行,从而产生一个空字符串。是否有可能在此函数中包含某种类型的逻辑或语句,使其在返回值之前等待响应?有没有一个框架来处理这种类型的东西?Actionscript等待异步事件函数
- 呼叫服务
- 解析JSON结果,隔离感兴趣
值返回值
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 }