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

flex webservice获取城市的天气情况

发布时间:2020-12-15 05:06:36 所属栏目:百科 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"?mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"layout="absolute"mx:Style global{ fontSize:12pt; } /mx:Stylemx:Script![CDATA[import mx.collections.ArrayCollection;import mx.controls.Alert;import
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				layout="absolute">
	<mx:Style>
  global{
   fontSize:12pt;
  }
 </mx:Style>

	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

			//引入远程调用的事件处理
			//向WebService发送请求

			private function sendCount():void
			{
				ws.getWeather.send();
			}

			//显示结果的处理函数
			private function showResult(rs:ResultEvent):void
			{
				//得到返回的结果
				var rsStr:ArrayCollection=ArrayCollection(rs.result);
				var info:String = "";
				for(var i:int=0;i<rsStr.length;i++) {
					info+=rsStr[i]+"n";
				}
				Alert.show(info);
				cityInfoText.text=rsStr[0];
			}

			private function faultResult(faultmessage:FaultEvent):void
			{

				var faultStr:String=new String(faultmessage.message);
				Alert.show(faultStr,"WebService访问错误");
			}

			private function go():void
			{
				navigateToURL(new URLRequest("http://www.webxml.com.cn/"),"_blank");
			}

			//清空查询信息
			private function clearText():void
			{
				cityCode.text=null;
				userid.text=null;
			}
		]]>
	</mx:Script>
	<!-- 引入WebService标签,设定wsdl。不使用代理名称-->
	<!--此 WebService由网站:http://www.webxml.com.cn/提供。该网站内还有其它免费web服务 -->
	<mx:WebService id="ws"
				   wsdl="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl"
				   useProxy="false"
				   showBusyCursor="true"
				   result="showResult(event)"
				   fault="faultResult(event)">

		 <mx:operation name="getWeather" resultFormat="object">
                <mx:request>
                   <theCityCode>{cityCode.text}</theCityCode>
      				<theUserID>{userid.text}</theUserID>
                </mx:request>
            </mx:operation>
	</mx:WebService>

	<mx:Panel x="296"
			  y="107"
			  width="364"
			  height="277"
			  layout="absolute"
			  title="城市天气查询"
			  horizontalAlign="center"
			  verticalAlign="middle">
		<mx:TextInput x="127"
					  y="33"
					  id="cityCode"/>
		<mx:Button x="114"
				   y="182"
				   label="查询"
				   click="sendCount()"/>
		<mx:Text x="35"
				 y="154"
				 text=""
				 width="299"
				 id="cityInfoText"/>
		<mx:Button x="174"
				   y="182"
				   label="清除"
				   id="clear"
				   click="clearText()"/>
		<mx:TextInput x="127" y="78" id="userid"/>
		<mx:Label x="35" y="35" text="城市ID/城市名"/>
		<mx:Label x="35" y="80" text="UserId"/>
	</mx:Panel>

	<mx:Text width="321"
			 height="50"
			 x="318"
			 y="37">
		<mx:htmlText>
			<![CDATA[
       <a href="http://blog.163.com/liwei3324@126/" target=" _blank">如有不懂的地方,欢迎访问我的博客。点击我</a>
      ]]>
		</mx:htmlText>
	</mx:Text>
	<mx:Label x="135"
			  y="403"
			  text="此WebService是由网站http://www.webxml.com.cn/提供"
			  fontSize="22"
			  fontWeight="bold"
			  fontStyle="italic"/>
	<mx:LinkButton x="404"
				   y="458"
				   label="走,去看看!>>"
				   color="#1510EC"
				   click="go()"/>
</mx:Application>

(编辑:李大同)

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

    推荐文章
      热点阅读