2016-10-13 00:16:48 点击量:29 标签: 收藏本文
在AS3中保留了原始的用法,setInterval()与setTimeout()依然是可以使用的,跟AS2.0有所不同的是增加了,Timer()方法。
时间间隔可以用 setInterval 命令来创建并用 clearInterval 命令来终止。setInterval 所用的参数有两种格式。在第一种格式中,你传递给 setInterval 的参数可以是一个函数名,一段时间上的间隔以及一些传递给前面函数的相关参数。当 setInterval 运行时它会依照规定的时间间隔依次将列出的参数传递给指定的函数,直到你调用 clearInterval 将其终止。
1、原始方法:
setInterval(closure:Function, delay:Number, ... arguments):uint
setTimeout(closure:Function, delay:Number, ... arguments):uint
注意返回类型是uint,所在CLASS:flash.utils.*
2、新方法:
- package
- {
- import flash.display.Sprite;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- public class ShortTimer extends Sprite
- {
- public function ShortTimer()
- {
- // creates a new five-second Timer
- var minuteTimer:Timer = new Timer(1000, 5);
- // designates listeners for the interval and completion events
- minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
- minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
- // starts the timer ticking
- minuteTimer.start();
- }
- public function onTick(evt:TimerEvent):void
- {
- // displays the tick count so far
- // The target of this event is the Timer instance itself.
- trace("tick " + evt.target.currentCount);
- }
- public function onTimerComplete(evt:TimerEvent):void
- {
- trace("CuPlayer.com提示:Time's Up!");
- }
- }
- }
- CuPlayer.com提示输出结果如下:
- tick 1
- tick 2
- tick 3
- tick 4
- tick 5
- CuPlayer.com提示:Time's Up!
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室