Flex/Actionscript定时Timer实践运用

来自help.adobe.com:

The Timer class is the interface to timers, which let you run code on a specified time sequence. Use the start() method to start a timer. Add an event listener for the timer event to set up code to be run on the timer interval.
 

 

运用它的关键地方:

 

1. 首先定义好timer对象

public var _timer:Timer = new Timer(3000, 1);/*定时3秒钟, 重复1次*/

 

timer对象的构造方法:

public function Timer(delay:Number, repeatCount:int = 0)

两个参数,delay:间隔时间单位为微妙,或是等待时间;repeatCount:重复次数,即指定timer计时器要作用几次。

repeatCount默认情况为0,可以无限次的使用,除非调用_timer.stop()。

 

2. 给timer对象新增事件监听,即时间到了要干的活

_timer.addEventListener(TimerEvent.TIMER, _onTimer);

private function _onTimer(e:TimerEvent):void
{
//add your statements              
}

 

3.之前两步是准备好所有的“作料”,下面是如何控制

   1)什么时候“按表”:_timer.start();

   2)什么时候“归零”:_timer.reset();

   3)  提前“停表”:_timer.stop();

 

正常的过程是start之后,设定的时间到了就触发_onTimer干活;

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值