废话不多说,上代码:

 

 
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"  
  3.                xmlns:s="library://ns.adobe.com/flex/spark"  
  4.                creationComplete="init()" 
  5.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
  6.     <fx:Script> 
  7.         <![CDATA[ 
  8.             import mx.collections.ArrayCollection; 
  9.             import mx.controls.Alert; 
  10.             import mx.rpc.events.FaultEvent; 
  11.             import mx.rpc.events.ResultEvent; 
  12.              
  13.             private function init():void 
  14.             {
     
  15.                 //天气预报 
  16.                 webService.getWeatherbyCityName("苏州"); 
  17.             } 
  18.              
  19.             /***************************天气预报***************************/ 
  20.             private function onLoad(event:ResultEvent):void{    
  21.                 var weatherInfo:ArrayCollection = (event.result) as ArrayCollection;    
  22.                 for(var i:int=0;i<weatherInfo.length;i++){  
  23.                     myWeatherReport.text+=weatherInfo[i]+" | ";    
  24.                 }    
  25.             } 
  26.              
  27.             private function faultHandler(event:FaultEvent):void{    
  28.                 Alert.show(event.fault.toString(),"WebService Error");    
  29.             } 
  30.              
  31.         ]]> 
  32.     </fx:Script> 
  33.      
  34.      
  35.     <fx:Declarations> 
  36.         <!-- 将非可视元素(例如服务、值对象)放在此处 --> 
  37.          
  38.         <s:WebService id="webService" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"    
  39.                       useProxy="false" showBusyCursor="true" result="onLoad(event)" fault="faultHandler(event)"/> 
  40.     </fx:Declarations> 
  41.      
  42.      
  43.     <!--天气预报--> 
  44.     <mx:Text styleName="weatherFont" id="myWeatherReport" x="450" y="60"/> 
  45. </s:Application>