<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:HBox>
<mx:Label text="CityName:"/>
<mx:ComboBox editable="true" id="cboCityName">
<mx:dataProvider>
<mx:Array>
<mx:String>选择输入</mx:String>
<mx:String>北京</mx:String>
<mx:String>长沙</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
<mx:Button id="btnQuery" label="Look for" click="onQuery()"/>
</mx:HBox>
<mx:TextArea editable="false" width="100%" height="80%" id="txtWeatherInfo"/>
<mx:WebService id="wsWeather" showBusyCursor="true"
wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"
fault="onFault(event)" result="onResult(event)"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.collections.ArrayCollection;
private function onQuery():void{
txtWeatherInfo.text ="";
wsWeather.getWeatherbyCityName(cboCityName.text);
}
private function onFault(event:FaultEvent):void{
Alert.show(event.message.toString(),"Fault");
}
private function onResult(event:ResultEvent):void{
var acWeatherInfo:ArrayCollection = event.result as ArrayCollection;
for(var i:uint=0;i<acWeatherInfo.length;i++){
txtWeatherInfo.text += acWeatherInfo.getItemAt(i)+"\n";
}
}
]]>
</mx:Script>
</mx:Application>
flex+webservice
最新推荐文章于 2021-03-04 02:21:01 发布