Flex经过WebService获取客户端的IP地址和天气状况
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>