2012-09-25 59 views
0

我想通過動作腳本創建HttpService的編程方式創建HTTP服務,我想這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中轉換它?

回答

0

這可以幫助你,請注意這裏的下面的代碼不使用綁定

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

感謝親愛的它的工作原理.. –