forked from: flash on 2010-2-28

by aiz forked from flash on 2010-2-28 (diff: 1)
♥0 | Line 67 | Modified 2014-02-01 21:52:33 | MIT License
play

ActionScript3 source code

/**
 * Copyright aiz ( http://wonderfl.net/user/aiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1SXI
 */

// forked from _ryotaros's flash on 2010-2-28
package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.events.Event;
    
    public class FlashTest extends Sprite {
            
            public var timeField:TextField;
            public var clocks:clock;
            
        public function FlashTest() {
           init();
        }
        
        public function init():void{
                
                clocks = new clock();
                
                this.graphics.beginFill(0x000000);
                this.graphics.drawRect(0,0,stage.stageWidth,50);
                this.graphics.endFill();
                
                timeField = new TextField;
                timeField.x =stage.stageWidth /2;
                timeField.y =stage.stageHeight /2;

                addChild(timeField);
                clocks.addEventListener("_timeUpdate",_timeUpdate);
        }
        public function _timeUpdate(e:Event):void{
                timeField.text = clocks.getTime();
        }
        
        public function updater():void{
        }
    }
}

import flash.display.Sprite;
import flash.events.Event;
class clock extends Sprite{
    
    public var date:Date;
    public var h:int;
    public var m:int;
    public var s:int;
    
    public function clock ():void{
        init();
    }
        
    public function init():void{
        date = new Date();
        h = date.hours;
        m = date.minutes;
        s = date.seconds;
        addEventListener(Event.ENTER_FRAME,_updater);
    }
    
    private function _updater(e:Event):void{
        var now:Date = new Date();
        if(now.hours != h){
            dispatchEvent(new Event("_hUpdate"));    
            h = now.hours;
        }
        if(now.minutes != m){
            dispatchEvent(new Event("_mUpdate"));    
            m = now.minutes;
        }
        if(now.seconds != s){
            dispatchEvent(new Event("_sUpdate"));    
            dispatchEvent(new Event("_timeUpdate"));
            s = now.seconds;
        }
        date = now;        
    }
    
    public function getTime():String {
        var t:String = date.hours + ":"+ date.minutes + ":" + date.seconds;
        return t;
    }
}