`
wecbk
  • 浏览: 31813 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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>

分享到:
评论
1 楼 hyx0914 2011-10-13  
没看明白。。。。

相关推荐

    flex actionscript 调用处理 webservice的过程及方法

    flex actionsript 调用webservice。以及flex处理webservice的过程及方法。

    将 Flex 集成到 Java EE 应用程序的最佳实践(完整源代码)

    Flex 支持多种远程调用方式,包括 HTTP,Web Services 和 AMF。不过,针对 Java EE 开发的服务器端应用,可以通过集成 BlazeDS,充分利用 AMF 协议并能轻易与 Flex 前端交换数据,这种方式是 Java EE 应用程序集成 ...

    flex客户端和服务端分页控件,后台java

    flex客户端和服务端分页控件,后台使用java实现数据的传送,flex客户端调用服务端的webservices服务进行数据的展现~~ 内附myeclipse项目和flex项目·~ 分别导入可运行,注意端口的修改~

    flex与java通信,通过插件blazed

    --flex与webservice交互这里调用一个天气预报的webservice--&gt; wsdl="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl" fault="ws_faultHandler(event)" result="ws_resultHandler(event)" ...

    +Flex+集成到+Java+EE+应用程序的最佳实践(完整源代码)

    Flex 支持多种远程调用方式,包括 HTTP,Web Services 和 AMF。不过,针对 Java EE 开发的服务器端应用,可以通过集成 BlazeDS,充分利用 AMF 协议并能轻易与 Flex 前端交换数据,这种方式是 Java EE 应用程序集成 ...

    Flex企业应用开发实战源代码

    本书对Flex的基础知识着墨不多,所有内容都围绕Flex+Java这一企业级应用开发技术展开,侧重于对Flex技术原理、企业级应用的架构思想和实现方法的讲解,所以书中的内容不会随着Flex版本的升级而过时。 第1章 Flex...

    Flex在线翻译和手机归属地查询(源码)

    利用webservices在线实现中英文互翻译和手机的归属地查询功能,良好的调用了Flex中的RPC服务组件的一个组件!

    Flash+C#在线拍照源码

    使用flex+fluorineFx+webservices(C#) 其中注意的是.net环境与flex环境的结合,fluorineFx的引用,端口的配置。代码是没多少难度的,网上有很多资料。 .net flex(FluorineFX) 项目建立参考: 1.唐勇[翻译]配置...

    Flex通过JS获取客户端IP和计算机名的实例代码

    首先说明一下,用JS方式获取不是调用webservices和httpservices。  在我们每一个FLex web工程中,都有那么一个文件夹bin-debug,里面有个index.html文件,我的个人理解是这样的,首先网页运行的时候,mxml的文件会...

    Flex_Spring3_Hibernate3整合Demo

    Flex_Spring3_Hibernate3整合Demo,使用RemoteObject调用java代码。主要配置为applicationContext.xml,web.xml,services-config.xml,remoting-config.xml。另外要引入SpringFactory类。

    Flash+C#在线拍照

    Flash+C#在线拍照源码使用flex+fluorineFx+webservices(C#)其中注意的是.net环境与flex环境的结合,fluorineFx的引用,端口的配置。代码是没多少难度的,网上有很多资料。.netflex(FluorineFX)项目建立参考:1....

    asp.net知识库

    自定义通用System.Web.UI.IHierarchicalDataSource简单实现 在 ASP.NET 2.0 中创建 Web 应用程序主题 ASP.NET 2.0 中的数据访问 ASP.NET 2.0:弃用 DataGrid 吧,有新的网格控件了! 将 ASP.NET 2.0 应用程序服务...

Global site tag (gtag.js) - Google Analytics