首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

Flex/Actionscript定时Timer实践应用

2012-10-09 
Flex/Actionscript定时Timer实践运用来自help.adobe.com: The Timer class is the interface to timers, w

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干活;

?

?

热点排行