Chinaunix首页 | 论坛 | 博客
  • 博客访问: 598505
  • 博文数量: 60
  • 博客积分: 3993
  • 博客等级: 中校
  • 技术积分: 1572
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 17:08
文章分类

全部博文(60)

文章存档

2012年(7)

2011年(35)

2010年(8)

2009年(7)

2008年(3)

分类: Python/Ruby

2011-02-05 17:28:13

呵呵,又见计时器,好怀念VB时代啊!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="" layout="absolute">
  3.     <mx:Script>
  4.         <![CDATA[
  5.             import flash.utils.Timer; //计时器,使用它在每次达到间隔时调度事件

  6.             import flash.events.TimerEvent; //Timer 对象在每次达到指定的间隔时都会调度 TimerEvent 对象


  7.             //控制时间间隔

  8.             private var m:Timer;
  9.             private var total:int=30;
  10.             private function clickBt1():void
  11.             {
  12.                 m = new Timer(1000,total); //创建一个每秒调度一个事件且持续 30 秒的 Timer 实例

  13.                 bt1.enabled = false;
  14.                 bt3.enabled = true;            
  15.                 m.addEventListener(TimerEvent.TIMER,onTick); //为间隔事件指定侦听器

  16.                 m.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete); //为完成事件指定侦听器

  17.                 m.start();    //启动计时器计时

  18.             }
  19.             
  20.             private function clickBt3():void
  21.             {
  22.                 m.stop();
  23.                 tx1.text="已停止";
  24.                 bt1.enabled = true;
  25.                 bt3.enabled = false;    
  26.             }
  27.             
  28.             private function onTick(event:TimerEvent):void //每次达到指定的间隔时都会调度TimerEvent对象,显示到目前为止的计时器计时次数

  29.             {
  30.                 tx1.text=String(event.target.currentCount) + "/" +String(total); //将计时次数显示在tx1中

  31.             }
  32.             
  33.             private function onTimerComplete(event:TimerEvent):void //在达到最后一次间隔时,调度timerComplete事件

  34.             {
  35.                 tx1.text="Complete!";
  36.                 bt1.enabled = true;
  37.                 bt3.enabled = false;
  38.             }
  39.             

  40.             private function clickBt2():void
  41.             {
  42.                 var now:Date = new Date();
  43.                 fullYear.text = String(now.fullYear) + "年";
  44.                 month.text = String(now.month+1) + "月";
  45.                 date1.text = String(now.date) + "日";
  46.                 var dayOfWeek:String;
  47.                 switch(now.day)
  48.                 {
  49.                     case 0:
  50.                         dayOfWeek="星期日";
  51.                         break;
  52.                     case 1:
  53.                         dayOfWeek="星期一";
  54.                         break;
  55.                     case 2:
  56.                         dayOfWeek="星期二";
  57.                         break;
  58.                     case 3:
  59.                         dayOfWeek="星期三";
  60.                         break;
  61.                     case 4:
  62.                         dayOfWeek="星期四";
  63.                         break;
  64.                     case 5:
  65.                         dayOfWeek="星期五";
  66.                         break;
  67.                     case 6:
  68.                         dayOfWeek="星期六";
  69.                         break;
  70.                     default:
  71.                         dayOfWeek="未知";
  72.                         break;
  73.                 }    
  74.                 day.text = dayOfWeek;
  75.                 hours.text = String(now.hours) + "时";
  76.                 minutes.text = String(now.minutes) + "分";
  77.                 seconds.text = String(now.seconds) + "秒";
  78.                 milliseconds.text = String(now.milliseconds) + "微秒";
  79.             }
  80.             
  81.         ]]>
  82.     </mx:Script>
  83.     <mx:TextInput x="58" y="43" id="tx1" width="170" text="计时器未启动"/>
  84.     <mx:Button x="58" y="84" label="启动计时器" id="bt1" click="{clickBt1()}"/>
  85.     <mx:Form x="264" y="43">
  86.         <mx:FormItem label="fullYear">
  87.             <mx:Label id="fullYear"/>
  88.         </mx:FormItem>
  89.         <mx:FormItem label="month">
  90.             <mx:Label id="month"/>
  91.         </mx:FormItem>
  92.         <mx:FormItem label="date">
  93.             <mx:Label id="date1"/>
  94.         </mx:FormItem>
  95.         <mx:FormItem label="day">
  96.             <mx:Label id="day"/>
  97.         </mx:FormItem>
  98.         <mx:FormItem label="hours">
  99.             <mx:Label id="hours"/>
  100.         </mx:FormItem>
  101.         <mx:FormItem label="minutes">
  102.             <mx:Label id="minutes"/>
  103.         </mx:FormItem>
  104.         <mx:FormItem label="seconds">
  105.             <mx:Label id="seconds"/>
  106.         </mx:FormItem>
  107.         <mx:FormItem label="milliseconds">
  108.             <mx:Label id="milliseconds"/>
  109.         </mx:FormItem>
  110.         <mx:Button label="获取时间单位值" id="bt2" click="{clickBt2()}"/>
  111.     </mx:Form>
  112.     <mx:Button x="147" y="84" label="停止计时器" id="bt3" enabled="false" click="{clickBt3()}"/>
  113. </mx:Application>
阅读(3866) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~