In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: デジタルクロック

Get Adobe Flash player
by mtkythr 17 Apr 2011
    Embed
/**
 * Copyright mtkythr ( http://wonderfl.net/user/mtkythr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/y0rW
 */

// forked from sa_1104's forked from: デジタルクロック
// forked from tsutaya42's デジタルクロック
package {
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.geom.Matrix;
    import flash.display.GradientType;
    import flash.display.StageQuality;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.filters.GlowFilter;
    
    [SWF(backgroundColor=0x000000, width=465, height=465)]
    public class DigiClock extends Sprite {
        private var matrix:Matrix;
        private var shape:Shape;
        private const STAGE_SIZE:uint = 465;
        private var startColor:uint = 0x003030;
        private var endColor:uint = 0x000000;
        private var tf:TextField;
        private var tfm:TextFormat;
        private var timer:Timer;
        
        public function DigiClock() {
            stage.quality = StageQuality.BEST;
            matrix = new Matrix();
            matrix.createGradientBox(STAGE_SIZE*1.5, STAGE_SIZE*1.5, 0, -100, -100);
            
            // Background
            shape = new Shape();
            shape.graphics.beginGradientFill(
                GradientType.RADIAL,
                [startColor, endColor],
                [1, 1],
                [0, 230],
                matrix
            );
            shape.graphics.drawRect(0, 0, STAGE_SIZE, STAGE_SIZE);
            shape.graphics.endFill();
            
            addChild( shape );
            
            // Stripe
            var stripe:Shape = new Shape();
            var interval:Number = 2;
            var i:uint;      
            while( stripe.height < STAGE_SIZE ) {
               with ( stripe.graphics ) {
                   lineStyle( 1, 0x000000 );
                   moveTo( 0, interval*i  );
                   lineTo( STAGE_SIZE, interval*i );
               }
               i++;
            }
            
            // TextField
            tfm = new TextFormat();
            tfm.color = 0x00faff;
            tfm.size = 80;
            tfm.font = "_sans";
            
            tf = new TextField();
            tf.defaultTextFormat = tfm;
            tf.autoSize = TextFieldAutoSize.CENTER;
            var glow:GlowFilter = new GlowFilter();
            glow.color = 0xffffff;
            glow.alpha = 0.3;
            glow.blurX = 15;
            glow.blurY = 15;
            glow.strength = 2;
            glow.quality = 3;
            tf.filters = [glow];
            tf.x = STAGE_SIZE / 2 - tf.textWidth;
            tf.y = STAGE_SIZE / 2 - Number( tfm.size );
            addChild( tf );
            addChild( stripe );
            
            // Timer
            timer = new Timer( 1000 );
            timer.addEventListener( TimerEvent.TIMER, upDateClock );
            timer.start();
        }
        
        private function upDateClock( e:TimerEvent ):void {
            var clock:ClockCore = new ClockCore;
            tf.text = clock.hours + ":" + clock.minutes + ":" + clock.seconds;
        }
    }
}

import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;

class ClockCore extends Sprite
{
    private var date:Date = new Date();
    
    public function ClockCore() {
        date = new Date();
    }
    
    public function get day():uint {
        return date.day;
    }
    
    public function get hours():String {
        if( date.hours >= 12 ) {
            return zeropad( date.hours - 12 );
        } else {
            return zeropad( date.hours );
        }
    }
    
    public function get minutes():String {
        return zeropad( date.minutes );
    }

    public function get seconds():String {
        return zeropad( date.seconds );
    }
    
    public function get ampm():String {
        if( date.hours >= 12 ) {
            return "PM";
        } else {
            return "AM";
        }
    }
    
    private function zeropad( number:Number ):String
    {
        var str:String = String( number );
        
        if( str.length == 1 ) {
            return "0" + str;
        } else {
            return str;
        }
    }
}