用flex怎样调用天气预报的web服务
1个回答
展开全部
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="20">
<mx:WebService id="weatherWebService" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl" showBusyCursor="true" result="onLoad(event)" fault="faultHandler(event)"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
private function onLoad(e:ResultEvent):void{
var weatherInfo:ArrayCollection=(e.result) as ArrayCollection;
for(var i:int=0;i<weatherInfo.length;i++){
cityWeather.text+=weatherInfo[i]+"\n";
}
}
private function faultHandler(e:FaultEvent):void{
Alert.show(e.fault.toString(),"WebService Error");
}
private function findWeather():void{
cityWeather.text="";
weatherWebService.getWeatherbyCityName(cityName.text);
}
]]>
</mx:Script>
<mx:TextInput x="10" y="53" id="cityName"/>
<mx:Button x="178" y="53" label="查询" click="findWeather()"/>
<mx:TextArea x="10" y="96" width="665" height="362" id="cityWeather"/>
</mx:WindowedApplication>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="20">
<mx:WebService id="weatherWebService" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl" showBusyCursor="true" result="onLoad(event)" fault="faultHandler(event)"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.rpc.events.FaultEvent;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
private function onLoad(e:ResultEvent):void{
var weatherInfo:ArrayCollection=(e.result) as ArrayCollection;
for(var i:int=0;i<weatherInfo.length;i++){
cityWeather.text+=weatherInfo[i]+"\n";
}
}
private function faultHandler(e:FaultEvent):void{
Alert.show(e.fault.toString(),"WebService Error");
}
private function findWeather():void{
cityWeather.text="";
weatherWebService.getWeatherbyCityName(cityName.text);
}
]]>
</mx:Script>
<mx:TextInput x="10" y="53" id="cityName"/>
<mx:Button x="178" y="53" label="查询" click="findWeather()"/>
<mx:TextArea x="10" y="96" width="665" height="362" id="cityWeather"/>
</mx:WindowedApplication>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询