2016-10-13 00:16:48 点击量:7 标签: 收藏本文
as3 Timer的暂停,[as3]as3中Timer的运行与暂停操作
- /*
- ~~ 星辰脈動 - Starpulse ~~
- */
- package {
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.IEventDispatcher;
- import flash.events.TimerEvent;
- import flash.utils.Timer;
- import flash.utils.getTimer;
- /**
- * The <code>MyTimer</code> class.<br/>
- */
- public class MyTimer implements IEventDispatcher {
- //==========================================================================
- // Constructor
- //==========================================================================
- /** Constructor */
- public function MyTimer(delay:Number, repeatCount:int = 0) {
- super();
- $timer = new Timer(delay, repeatCount);
- $startTime = NaN;
- $past = NaN;
- $correct = false;
- $timer.addEventListener(TimerEvent.TIMER, timerHandler, false, int.MAX_VALUE);
- }
- //==========================================================================
- // Properties
- //==========================================================================
- private var $correct:Boolean;
- private var $past:Number;
- private var $startTime:Number;
- private var $delay:Number;
- private var $timer:Timer;
- //==========================================================================
- // Public methods
- //==========================================================================
- public function reset():void {
- $startTime = NaN;
- $past = NaN;
- $timer.reset();
- }
- public function stop():void {
- if(!$timer.running)
- return;
- $past = getTimer() - $startTime;
- $timer.stop();
- }
- public function start():void {
- if(isNaN($startTime)) {
- $startTime = getTimer();
- } else {
- $delay = $timer.delay;
- $timer.delay = $timer.delay - ((getTimer() - $startTime) % $timer.delay);
- $correct = true;
- }
- $timer.start();
- }
- public function dispatchEvent(event:Event):Boolean {
- return $timer.dispatchEvent(event);
- }
- public function addEventListener(type:String, listener:Function, useCapture:Boolean = false,
- priority:int = 0, useWeakReference:Boolean = false):void {
- $timer.addEventListener(type, listener, useCapture, priority, useWeakReference);
- }
- public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void {
- $timer.removeEventListener(type, listener, useCapture);
- }
- public function willTrigger(type:String):Boolean {
- return $timer.willTrigger(type);
- }
- public function hasEventListener(type:String):Boolean {
- return $timer.hasEventListener(type);
- }
- //==========================================================================
- // Event Listeners
- //==========================================================================
- private function timerHandler(event:Event):void {
- if($correct) {
- $timer.delay = $delay;
- $correct = false;
- }
- }
- } // <- end class ->
- }
- //
as3 Timer的暂停,[as3]as3中Timer的运行与暂停操作
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室