【问题标题】:could not be able to create http service programmatically in flex无法在 flex 中以编程方式创建 http 服务
【发布时间】:2012-09-25 15:42:55
【问题描述】:

我正在尝试通过动作脚本创建 HttpService,并且我想将此 mxml 代码转换为我的动作脚本 mxml代码代码在这里:

<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>

如何在 actionscript 中转换?

【问题讨论】:

    标签: flex4.5 httpservice


    【解决方案1】:

    这可能会对您有所帮助,请注意以下代码未使用绑定

            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");
            }
    

    【讨论】:

      猜你喜欢
      • 2014-05-26
      • 1970-01-01
      • 2017-12-30
      • 2015-01-24
      • 1970-01-01
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多