加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flex调用webservice(以天气预报为例)

发布时间:2020-12-15 05:10:19 所属栏目:百科 来源:网络整理
导读:建一个文件,WeatherService.mxml,内容如下 ?xml version="1.0" encoding="utf-8"? mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" initialize="init()" ?mx:Script ??![CDATA[ ???import mx.rpc.events.ResultEvent; ???i

建一个文件,WeatherService.mxml,内容如下

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" initialize="init()">
?<mx:Script>
??<![CDATA[
???import mx.rpc.events.ResultEvent;
???import mx.collections.ArrayCollection;
???import mx.rpc.events.FaultEvent;
???import mx.controls.Alert;
???private function init():void{
????myService.getWeatherbyCityName(ContactsConst.CURRENT_CITY_NAME);
???}
???private function getWeatherResult(event:ResultEvent):void{
????var arr:ArrayCollection=ArrayCollection(event.result);//结果是一个包含字符串的集合
????cityName.text=String(arr[1]);//第二个字符串是城市名称
????todayWeather.text=String(arr[6]);//第六个是 当天日期和天气 类似这样2月20日 晴转多云
????todayTemp.text=String(arr[5]);//第五个是 温度
????tomoWeather.text=String(arr[13]);
????tomoTemp.text=String(arr[12]);
????afterWeather.text=String(arr[18]);
????afterTemp.text=String(arr[17]);
???}
???private function getFault(event:FaultEvent):void{
????Alert.show("网络连接错误!"+event.fault.message,"提示");
???}
??]]>
?</mx:Script>
?<mx:WebService id="myService" showBusyCursor="true" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl" useProxy="false"> ??<mx:operation name="getWeatherbyCityName" result="getWeatherResult(event)" fault="getFault(event)"/> ?</mx:WebService> ?<mx:HBox width="100%" horizontalAlign="center"> ??<mx:Label id="cityName" fontSize="13"/> ??<mx:Label id="todayWeather" fontSize="13"/> ??<mx:Label id="todayTemp" fontSize="13"/> ??<mx:Label id="tomoWeather" fontSize="13"/> ??<mx:Label id="tomoTemp" fontSize="13"/> ??<mx:Label id="afterWeather" fontSize="13"/> ??<mx:Label id="afterTemp" fontSize="13"/> ?</mx:HBox> </mx:VBox>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读