本文介绍了在Flex中无法以编程方式创建http服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过操作脚本创建HttpService,我想将此mxml代码转换为我的操作脚本mxml代码位于此处:
I'm trying to create HttpService through Action Script and I want to convert this mxml code to my Action Scriptmxml code code is here:
<s:HTTPService id="weatherService"
url="{BASE_URL}"
resultFormat="object"
result="weatherService_resultHandler(event)"
fault="weatherService_faultHandler(event)"
showBusyCursor="true">
<s:request xmlns="">
<q>{cityName.text.toString()}</q>
<format>{FORMAT}</format>
<num_of_days>{NUMBER_OF_DAYS}</num_of_days>
<key>{API_KEY}</key>
</s:request>
</s:HTTPService>
如何在动作脚本中进行转换?
How to convert this in actionscript?
推荐答案
这可能会对您有所帮助,请在此处注意以下代码未使用绑定
This might help you and please note here the following code not using binding
import mx.rpc.http.HTTPService;
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");
}
protected function weatherService_faultHandler(event:FaultEvent):void
{
trace("got fault");
}
这篇关于在Flex中无法以编程方式创建http服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!