我很清楚如何在 flex 中使用 HTTP 服务,但我想将调用服务的功能和在不同的 ActionScript 类中获取服务的响应分开。那么有谁知道我如何在 flex 中返回 HTTP 服务的响应?
例如
在 UTILITY 类中,我想要一种方法,我会给它一个 URL,它会给我从那个位置获得的数据。就是这样。考虑以下代码片段。取自的参考代码无法在 flex 中以编程方式创建 http 服务
private function callService():void
{
var requestObj:Object = {};
requestObj.q = cityName.text.toString();
requestObj.format = FORMAT;
requestObj.num_of_days = cNUMBER_OF_DAYS;
requestObj.key = API_KEY;
var weatherService:HTTPService = new HTTPService();
weatherService.url = BASE_URL;
weatherService.resultFormat = "object";
weatherService.showBusyCursor = true;
weatherService.request = requestObj;
weatherService.addEventListener(ResultEvent.RESULT , weatherService_resultHandler);
weatherService.addEventListener(FaultEvent.FAULT, weatherService_faultHandler);
weatherService.send();
}
protected function weatherService_resultHandler(event:ResultEvent):void
{
trace("got result");
**//WANT TO GIVE THIS RESULT BACK TO THE CALLER. SINCE RETURN TYPE OF
//METHOD IS VOID I CANNOT RETURN ANYTHING FROM HERE. HOW TO MAKE THIS
//METHOD TO RETURN DATA?**
}
protected function weatherService_faultHandler(event:FaultEvent):void
{
trace("got fault");
}