Flex通过WebService获取客户端的IP地址和天气状况

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
				layout="absolute"
				initialize="ini()">
	<mx:WebService id="ws"
				   wsdl="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"
				   fault=";"
				   result="result(event)"/>
	<mx:WebService id="ws2"
				   wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"
				   showBusyCursor="true"
				   fault=";">
		<mx:operation name="getSupportProvince"
					  result="result2(event)"/>
		<mx:operation name="getSupportCity"
					  result="result3(event)"/>
		<mx:operation name="getWeatherbyCityName"
					  result="result4(event)"/>
	</mx:WebService>

	<mx:Script>
		<![CDATA[
			import mx.events.ListEvent;
			import mx.utils.StringUtil;
			import mx.collections.ArrayCollection;
			import mx.rpc.events.ResultEvent;

			private function ini():void
			{
				ws2.getSupportProvince("");
			}

			private function result(e:ResultEvent):void
			{
				var ar:ArrayCollection=e.result as ArrayCollection;
				txt.text="ip:" + ar[0] + "   地址:" + ar[1];
			}

			private function result2(e:ResultEvent):void
			{
				var ar:ArrayCollection=e.result as ArrayCollection;
				cboProvince.dataProvider=ar;
			}

			private function result3(e:ResultEvent):void
			{
				var ar:ArrayCollection=e.result as ArrayCollection;
				cboCity.dataProvider=ar;
			}

			private function result4(e:ResultEvent):void
			{
				var ar:ArrayCollection=e.result as ArrayCollection;
				ta.text="[ "
				for (var i:int=0, len:int=ar.length; i < len; i++)
				{
					if (i == len - 1)
					{
						ta.text+=ar[i] + " ]";
						break;
					}
					ta.text+=ar[i] + " ] , [ "
				}
			}

			private function provinceFunc(item:Object):String
			{
				var s:String=item as String;
				if (s.indexOf("(") > 0)
				{
					s=StringUtil.trim(s.substring(0, s.indexOf("(")));
				}
				return s;
			}

			private function changePro(e:ListEvent):void
			{
				ws2.getSupportCity(cboProvince.text)
			}
		]]>
	</mx:Script>
	<mx:VBox>
		<mx:HBox>
			<mx:TextInput id="txt"/>
			<mx:Button label="getIp"
					   click="ws.getGeoIPContext()"/>
		</mx:HBox>
		<mx:HBox>
			<mx:ComboBox id="cboProvince"
						 change="changePro(event)"
						 labelFunction="provinceFunc"/>
			<mx:ComboBox id="cboCity"
						 labelFunction="provinceFunc"/>
			<mx:Button label="getWeather"
					   enabled="{cboCity.text!=''}"
					   click="ws2.getWeatherbyCityName(cboCity.text)"
					   x="359"
					   y="146"/>
		</mx:HBox>
		<mx:TextArea height="300"
					 id="ta"
					 width="400"/>
	</mx:VBox>
</mx:Application>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值