2012-09-25 3 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> 

액션 스크립트에서 이것을 어떻게 변환합니까?

답변

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

덕분에 바인딩을 사용하지 여기에 다음 코드를 참고하시기 바랍니다 있습니다 .. –