flex调用WebServices实现天气预报

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init(),rightKey()" backgroundImage="images/mcsh.jpg">
 <mx:Style>
  TextArea{
   border:5 double red;
   font-family:华文行楷;
   color:red;
   font-size:12px;
  }
  Label{
      color:#F8A10B;
    }
    Alert{
      font-size:12px;
    }
 </mx:Style>  
 <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;
      import flash.ui.ContextMenu;
          import flash.ui.ContextMenuItem;
          import flash.events.ContextMenuEvent;
          //在全局上定义四个菜单条目
      private var myMenuItem1:ContextMenuItem;
      private var myMenuItem2:ContextMenuItem;
      private var myMenuItem3:ContextMenuItem;
      private var myMenuItem4:ContextMenuItem;
      private var myMenuItem5:ContextMenuItem;
      private var myMenuItem6:ContextMenuItem;
      private var myMenuItem7:ContextMenuItem;
      private var myMenuItem8:ContextMenuItem;
      /**
       * 开始初始化鼠标右键
       */
        private function rightKey():void{
          /* ContextMenuItem类的构造函数要传入几个参数,它们分别代表
             1 菜单项的名称
             2 在该菜单项上是否显示分隔条,默认是不显示
             3 是否可用,默认是可用的
             4 是否显示,默认是可显示的
          */
          myMenuItem1 = new ContextMenuItem('麻城一中',true);
          myMenuItem2 = new ContextMenuItem('黄冈中学',true);
          myMenuItem3 = new ContextMenuItem('中国移动湖北网上营业厅',true);
          myMenuItem4 = new ContextMenuItem('湖北省人民政府',true);
          myMenuItem5 = new ContextMenuItem('全国公交查询网',true);
          myMenuItem6 = new ContextMenuItem('感动中国官方网站',true);
          myMenuItem7 = new ContextMenuItem('搜狐体育',true);
          myMenuItem8 = new ContextMenuItem('汽车之家',true);
        
          //添加事件侦听,以此来进行相应的逻辑实现
          myMenuItem1.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem2.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem3.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem4.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem5.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem6.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem7.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
          myMenuItem8.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,menuItemHandler);
        
          //创建个性化的菜单
          var myMenu:ContextMenu = new ContextMenu();
          myMenu.customItems.push(myMenuItem1);
          myMenu.customItems.push(myMenuItem2);
          myMenu.customItems.push(myMenuItem3);
          myMenu.customItems.push(myMenuItem4);
          myMenu.customItems.push(myMenuItem5);
          myMenu.customItems.push(myMenuItem6);
          myMenu.customItems.push(myMenuItem7);
          myMenu.customItems.push(myMenuItem8);
          //如果要隐藏默认的菜单项,可以这样设置
          myMenu.hideBuiltInItems();
          //这样是整个舞台都可以显示出相应的右键菜单
          this.contextMenu = myMenu;
        }
      //导航逻辑
      private function menuItemHandler(event:ContextMenuEvent):void{
       switch (event.target){
         case myMenuItem1:
          navigateToURL(new URLRequest('http://www.mcyz.com/'));
          break;              
         case myMenuItem2:
          navigateToURL(new URLRequest('http://www.hbshgzx.com/'));
         break;     
         case myMenuItem3:
          navigateToURL(new URLRequest('http://www.hb.chinamobile.com/'));
          break;     
         case myMenuItem4:
          navigateToURL(new URLRequest('http://www.hubei.gov.cn/'));
          break;     
         case myMenuItem5:
          navigateToURL(new URLRequest('http://www.8684.com/'));
          break;     
         case myMenuItem6:
          navigateToURL(new URLRequest('http://www.lovegdzg.com/index.asp'));
          break;
         case myMenuItem7:
          navigateToURL(new URLRequest('http://sports.sohu.com/'));
          break;
         case myMenuItem8:
          navigateToURL(new URLRequest('http://www.autohome.com.cn/'));
          break;
       }
      }
      /**
       * 日期和时间函数
       */            
   private function resetNow(event:TimerEvent):void {      
    // 获取登录时间和日期   
       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;     
       //this.clock.text = time;   
         }
         private function getDate():void{
          //设定时间
    var timer:Timer = new Timer(1000);      
    timer.addEventListener(TimerEvent.TIMER, this.resetNow);                       
    timer.start();
         }           
   /*根据城市查询天气  */
   private function query():void{
    if(txtCity.text==""){
     Alert.show("对不起,请您输入城市名称","友情提示");
     return;
    }
    wsWeather.getWeatherbyCityName(txtCity.text);
   }
  
   /* 初始化查询北京三天天气 */
   private function init():void{
    wsWeather.getWeatherbyCityName("武汉");
   }
  
   /* 显示今天-明天-后天三天天气 */
   private function resultHandle(evt:ResultEvent):void{
    var arr:ArrayCollection=ArrayCollection(evt.result);    
       this.lblCity.text=arr[0]+"-"+arr[1];
    //今天天气
       this.lblDate.text=arr[6];//日期
       this.lblwd.text="温度:"+arr[5];//温度
       this.lblfl.text=arr[7]; //风力
       this.imgToday.source="images/weather/a_"+arr[8];//图片
       this.imgToday2.source="images/weather/a_"+arr[9];//图片2
       this.taDetail.text="        "+arr[10];
       //明天天气
       this.lblDate1.text=arr[13];
       this.lblwd1.text=arr[12];
       this.lblfl1.text=arr[14];
       this.imgTomorrow.source="images/weather/a_"+arr[15];
       this.imgTomorrow2.source="images/weather/a_"+arr[16];
       this.taDetail1.text=arr[11];
       //后天天气
       this.lblDate2.text=arr[18];
       this.lblwd2.text=arr[17];
       this.lblfl2.text=arr[19];
       this.imgAfterTomorrow.source="images/weather/a_"+arr[20];
       this.imgAfterTomorrow2.source="images/weather/a_"+arr[21];
       this.taDetail2.text="        "+arr[22];
   }
   private function faultHandle(evt:FaultEvent):void{
       Alert.show("很抱歉,请您检查网络连接...");
   }
  ]]>
 </mx:Script>
 <mx:Iris id="iris" target="{weatherPanel}"></mx:Iris>
 <mx:Panel id="weatherPanel" width="620" height="632" layout="absolute" creationCompleteEffect="iris" title="凌晨雨薇--全国城市天气预报" fontSize="12" titleIcon="@Embed('images/weather/0.gif')">
  <mx:HRule x="10" y="65" width="580"/>
  <mx:Label x="76" y="42" text="今 天" width="38" fontWeight="bold" color="#030303"/>
  <mx:Label x="487" y="42" text="后 天" width="42" fontWeight="bold" color="#030303"/>
  <mx:Label x="280.25" y="42" text="明 天" width="43.5" fontWeight="bold" color="#030303"/>
    <mx:Canvas x="10" y="72" width="168" height="196" borderStyle="solid" borderColor="#111AC6">
      <mx:Label x="10" y="10" width="146" id="lblDate"/>
   <mx:Label x="10" y="38" width="146" height="24" id="lblwd"/>
   <mx:Label x="10" y="70" id="lblfl" width="146" height="29"/>
   <mx:Image x="8" y="120" width="70" height="65" id="imgToday"/>
   <mx:Image x="86" y="120" width="70" height="65" id="imgToday2"/>
    </mx:Canvas>
 
  <mx:Canvas x="216" y="72" width="168" height="196" borderStyle="solid" borderColor="#111AC6">
   <mx:Label x="10" y="10" width="146" id="lblDate1"/>
   <mx:Label x="10" y="38" width="146" height="24" id="lblwd1"/>
   <mx:Label x="10" y="70" id="lblfl1" width="146" height="29"/>
   <mx:Image x="8" y="120" width="70" height="65" id="imgTomorrow"/>
   <mx:Image x="86" y="120" width="70" height="65" id="imgTomorrow2"/>
  </mx:Canvas>
 
  <mx:Canvas x="422" y="72" width="168" height="196" borderStyle="solid" borderColor="#111AC6">
   <mx:Label x="11" y="10" width="146" id="lblDate2"/>
   <mx:Label x="10" y="38" width="146" height="24" id="lblwd2"/>
   <mx:Label x="10" y="70" id="lblfl2" width="146" height="29"/>
   <mx:Image x="8" y="119" width="70" height="65" id="imgAfterTomorrow"/>
   <mx:Image x="86" y="119" width="70" height="65" id="imgAfterTomorrow2"/>
  </mx:Canvas>
  <mx:TextInput x="88" y="10" id="txtCity" text="武汉" width="119"/>
  <mx:Button x="215" y="10" label="查 询" id="btnQuery" click="query()" borderColor="#0099ff"/>
  <mx:Label x="10" y="12" text="请输入城市:" width="88"/>
  <mx:Label x="280.25" y="11" width="146" height="24" fontWeight="bold" color="#FD060C" id="lblCity"/>
  <mx:TextArea x="10" y="290" width="580" height="54" id="taDetail" editable="false"/>
  <mx:TextArea x="10" y="366" width="580" height="85" id="taDetail1" editable="false"/>
  <mx:TextArea x="10" y="474" width="580" height="106" id="taDetail2" editable="false"/>
  <mx:Label x="10" y="347" text="指数信息栏" color="#0099ff"/>
  <mx:Label x="10" y="454" id="lblCityInfo" text="{txtCity.text}市简介" color="#0099ff"/>
  <mx:Label x="10" y="271" text="详细天气情况" color="#0099ff"/>
  <!--当前时间-->
  <!--<mx:Text id="clock" text="" creationComplete="this.getDate()" right="1" height="20" width="91" top="11"/>-->      
    <mx:Text id="date" text="" creationComplete="this.getDate()" right="10" height="20" width="167" top="11"/>
 </mx:Panel>
 <mx:WebService id="wsWeather" wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl" showBusyCursor="true" result="resultHandle(event)" fault="faultHandle(event)"/>
</mx:Application>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值