チェンジセット 3610

差分発生行の前後
無視リスト:
コミット日時:
2010/03/26 01:33:56 (3 年前)
コミッタ:
hkrn
ログメッセージ:

use TimerEvent? instead of setInterval

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • as3/gunyarapaint/branches/gunyarapaint/framework/src/org/libspark/gunyarapaint/framework/Player.as

    r3583 r3610  
    11package org.libspark.gunyarapaint.framework 
    22{ 
     3    import flash.events.TimerEvent; 
    34    import flash.utils.ByteArray; 
     5    import flash.utils.Timer; 
    46    import flash.utils.clearInterval; 
    57    import flash.utils.setInterval; 
     
    2123            parser.preload(); 
    2224            speed = 1; 
    23             duration = 50
    24             m_timerID = 0
     25            m_timer = new Timer(50)
     26            m_timer.addEventListener(TimerEvent.TIMER, process)
    2527            m_parser = parser; 
    2628            var version:uint = data.version; 
     
    5557        public function start():void 
    5658        { 
    57             if (m_timerID === 0) { 
    58                 m_timerID = flash.utils.setInterval(process, duration); 
     59            if (!m_timer.running) { 
     60                m_timer.start(); 
    5961                if (hasEventListener(PlayerEvent.STARTED)) 
    6062                    dispatchEvent(new PlayerEvent(PlayerEvent.STARTED)); 
     
    7274        public function pause():void 
    7375        { 
    74             stopTimer(); 
    75             if (hasEventListener(PlayerEvent.PAUSED)) 
    76                 dispatchEvent(new PlayerEvent(PlayerEvent.PAUSED)); 
     76            if (m_timer.running) { 
     77                m_timer.stop(); 
     78                if (hasEventListener(PlayerEvent.PAUSED)) 
     79                    dispatchEvent(new PlayerEvent(PlayerEvent.PAUSED)); 
     80            } 
    7781        } 
    7882         
     
    8791        public function stop():void 
    8892        { 
    89             stopTimer(); 
    90             m_parser.rewind(); 
    91             m_parser.resetCommands(); 
    92             if (hasEventListener(PlayerEvent.STOPPED)) 
    93                 dispatchEvent(new PlayerEvent(PlayerEvent.STOPPED)); 
     93            if (m_timer.running) { 
     94                m_timer.stop(); 
     95                m_parser.rewind(); 
     96                m_parser.resetCommands(); 
     97                if (hasEventListener(PlayerEvent.STOPPED)) 
     98                    dispatchEvent(new PlayerEvent(PlayerEvent.STOPPED)); 
     99            } 
    94100        } 
    95101         
    96         private function process():void 
     102        private function process(event:TimerEvent):void 
    97103        { 
    98104            try { 
     
    107113            } 
    108114            catch (e:Error) { 
    109                 stopTimer(); 
     115                m_timer.stop(); 
    110116                if (e is EOLError) { 
    111117                    m_parser.rewind(); 
     
    120126                } 
    121127            } 
    122         } 
    123          
    124         private function stopTimer():void 
    125         { 
    126             flash.utils.clearInterval(m_timerID); 
    127             m_timerID = 0; 
    128128        } 
    129129         
     
    152152        public function get playing():Boolean 
    153153        { 
    154             return m_timerID != 0
     154            return m_timer.running
    155155        } 
    156156         
     
    162162         
    163163        /** 
    164          * ログの長さ 
     164         * 動作間隔(ミリ秒) 
    165165         *  
    166166         */ 
    167         public var duration:uint; 
     167        public function set duration(value:uint):void 
     168        { 
     169            m_timer.delay = value; 
     170        } 
    168171         
    169172        private var m_parser:Parser; 
    170         private var m_timerID:uint
     173        private var m_timer:Timer
    171174    } 
    172175}