flex 全球天气预报小程序(自己开发)

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
						layout="horizontal" 
						width="660" height="720"
						creationComplete="init(),getIp()" >
	
	<mx:Script>
		<![CDATA[
		import mx.controls.Alert;
		import mx.collections.ArrayCollection;
		import mx.rpc.events.FaultEvent;
		import mx.rpc.events.ResultEvent;
		import mx.formatters.DateFormatter;      
		import flash.utils.Timer;   
		import flash.events.TimerEvent;                 
		
		[Bindable]
		private var pros:ArrayCollection = new ArrayCollection();
		[Bindable]
		private var cities:ArrayCollection = new ArrayCollection();
		
		//Initillization
		private function init():void {
			addEventListener(KeyboardEvent.KEY_DOWN, onEnterHandler);
			wsWeather.getWeatherbyCityName("Beijing");
		//wsWeather.getSupportProvince();
		}  
		
		// Enter key Event Handler
		private function onEnterHandler(event:KeyboardEvent):void {			
			if (event.keyCode == Keyboard.ENTER){
				query();
			}
		}
		
		//ResultHandler
		private function resultHandler( evt:ResultEvent ):void {
			pros = evt.result as ArrayCollection;
			var arr:ArrayCollection = ArrayCollection(evt.result);    
			this.lblCity.text = arr[0] + "-" + arr[1];
			this.city.source = "http://www.cma.gov.cn/tqyb/img/city/" + arr[3];
			//Weather of Today
			this.lblDate.text = arr[6];
			this.lblwd.text = "Temp:" + arr[5];
			this.lblfl.text = arr[7]; 
			this.img1.source = "assets/images/weather/" + arr[8];
			this.img2.source = "assets/images/weather/" + arr[9];
			//Weather of Tomorrow
			this.lblDate1.text = arr[13];
			this.lblwd1.text = "Temp:" + arr[12];
			this.lblfl1.text = arr[14];	    
			this.img3.source = "assets/images/weather/" + arr[15];
			this.img4.source = "assets/images/weather/" + arr[16];
			//Weather of The day after tomorrow
			this.lblDate2.text = arr[18];
			this.lblwd2.text = "Temp:" + arr[17];
			this.lblfl2.text = arr[19];
			this.img5.source = "assets/images/weather/" + arr[20];
			this.img6.source = "assets/images/weather/" + arr[21];
			
			this.txtIndex.text = arr[11];
			this.txtWeaDetail.text = "        " + arr[10];
			this.txtCityInfo.text = "        " + arr[22];
		}
		//FaultHandler
		private function faultHandler( evt:FaultEvent ):void {
			Alert.show("Sorry.Remote Connetion is unavailable now. Please try it later","Warning Message");
		}
		//Set time
		private function resetNow(event:TimerEvent):void {      
			// get current date and time
			var dateFormatter:DateFormatter = new DateFormatter();    
			dateFormatter.formatString = "YYYY-MM-DD JJ:NN:SS";   
			var time:String = new Date().toLocaleTimeString();   
			var date:String = dateFormatter.format(new Date());   
			this.date.text = date;     
		}
		private function getDate():void{
			//set clock time
			var timer:Timer = new Timer(1000);      
			timer.addEventListener(TimerEvent.TIMER, this.resetNow);                       
			timer.start();
		}           
		//Button Search Clicked handler
		private function query():void {
			if(txtCity.text  == "") {
			Alert.show("Please input a city name!","*Message Tips*");
			return;
			}
			
			wsWeather.getWeatherbyCityName(txtCity.text);
		}
		public function onComplete(event:ResultEvent):void{
			var ipInfo:ArrayCollection = (event.result) as ArrayCollection; 
			ip.text = ipInfo[0];
			address.text = ipInfo[1];
			var addr : String = ipInfo[1];
			var cityPattern:RegExp = /(.*省|.{0})(.*)市/;
			var rs:Object = cityPattern.exec(addr);
			var realAddr:String = rs[2];        
		}
		private function getIp():void{       
			ipWwebService.getGeoIPContext();
		}
		
		]]>
	</mx:Script>
	
	<mx:Style source="assets/css/styles.css" />
	<!--WebService-->
	<mx:WebService id="wsWeather" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl"
				   showBusyCursor="true" 
				   result="resultHandler(event)" 
				   fault="faultHandler(event)"/>
	<mx:WebService id="ipWwebService" wsdl="http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl"
				   showBusyCursor="true" result="onComplete(event)" fault="faultHandler(event)"/>
	<mx:Panel  width="100%" height="100%" 
			   layout="absolute" 
			   title="Weather Forecast All Around the World" 
			   fontSize="12" >
		<!--Header Part-->
		<mx:Canvas top="0"> 
			<mx:TextInput x="10" y="10" id="txtCity" text="Beijing" width="119" toolTip="Please input a City Name"/>
			<mx:Button x="137" y="10" label="Search" id="btnQuery" click="query()" 
					   buttonMode="true" 
					   toolTip="Press Enter to Search"
					   borderColor="#0099ff"/>
			
			<mx:Label x="10" y="38" width="206.25" height="24" fontWeight="bold" color="#FD060C" id="lblCity"/> 
			<mx:Text id="date" text="" creationComplete="this.getDate()" right="1" height="20" width="167" top="2" color="red"/>
			<mx:Image id="city" x="226.25" y="3" width="140.75" height="69"/>
			<mx:Label x="390" y="23" text="IP:" width="53" height="24" fontWeight="bold" truncateToFit="true" textAlign="right" paddingTop="4"/>
			<mx:Label x="378" y="48" text="Location:" height="24"  textAlign="right" paddingTop="4"/>
			<mx:Text x="449" y="26" id="ip" width="120" height="24" color="#6E8ADE"/>
			<mx:Text x="450" y="53" width="120" id="address" height="24" color="#6E8ADE"/>
			
		</mx:Canvas>
		<!--Weather Info of Three Days-->
		<mx:HBox top="90" left="80" horizontalGap="90" width="100%">  	    
			<mx:Label  text="Today"   fontWeight="bold" color="#000000"/>
			<mx:Label  text="Tomorrow"  fontWeight="bold" color="#cdcdcd" />
			<mx:Label  text="The Day After Tomorrow"   fontWeight="bold" color="#ffbdbd"/>
		</mx:HBox>
		
		<mx:HBox  y="111" x="20" >
			<!--Weather of Today-->
			<mx:Canvas  width="168" height="138" borderStyle="solid" borderColor="#111AC6">
				<mx:VBox left="10" horizontalAlign="center" verticalGap="10">  
					<mx:Label   width="146" height="24" id="lblDate" styleName="WeaToday"/>
					<mx:Label  width="146" height="24" id="lblwd" styleName="WeaToday"/>
					<mx:Label   id="lblfl" width="146" height="29" styleName="WeaToday"/> 
				</mx:VBox>
				<mx:HBox top="100" left="40" horizontalGap="20">		   
					<mx:Image id="img1" />
					<mx:Image id="img2"  />
				</mx:HBox>
			</mx:Canvas>
			<!--Weather of Tomorrow-->
			<mx:Canvas   width="168" height="138" borderStyle="solid" borderColor="#111AC6">
				<mx:VBox left="10" horizontalAlign="center" verticalGap="10">
					<mx:Label   width="146" id="lblDate1" styleName="WeaTomorrow"/>
					<mx:Label   width="146" height="24" id="lblwd1" styleName="WeaTomorrow"/>
					<mx:Label   id="lblfl1" width="146" height="29" styleName="WeaTomorrow"/>
				</mx:VBox>
				<mx:HBox top="100" left="40" horizontalGap="20">		   
					<mx:Image id="img3"  />
					<mx:Image id="img4"  />
				</mx:HBox>
			</mx:Canvas>
			
			<!--Weather of The day after tomorrow-->
			<mx:Canvas   width="168" height="138" borderStyle="solid" borderColor="#111AC6">
				<mx:VBox left="10" horizontalAlign="center" verticalGap="10">
					<mx:Label  width="146" id="lblDate2" styleName="WeaAfter"/>
					<mx:Label   width="146" height="24" id="lblwd2" styleName="WeaAfter"/>
					<mx:Label   id="lblfl2" width="146" height="29" styleName="WeaAfter"/>
				</mx:VBox>
				<mx:HBox top="100" left="40" horizontalGap="20">		   
					<mx:Image id="img5" />
					<mx:Image id="img6" />
				</mx:HBox>
			</mx:Canvas>    	
		</mx:HBox>
		
		<mx:VBox top="260" left="10" borderColor="#dedede">
			<mx:Label  text="今日综合指数信息概览" color="#0099ff"/>
			<mx:TextArea  width="570" height="85" id="txtIndex" editable="false"/>
			
			<mx:Label  text="今天的详细天气情况" color="#0099ff"/>
			<mx:TextArea   width="570" height="54" id="txtWeaDetail" editable="false"/>
			
			<mx:Label   id="lblCityInfo" text="{txtCity.text}市信息概览" color="#0099ff" />
			<mx:TextArea  width="570" height="98" id="txtCityInfo" editable="false"/>
			
		</mx:VBox>
		
	</mx:Panel>
	
</mx:WindowedApplication> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值