Digital_Clock

by sk310
♥0 | Line 68 | Modified 2011-07-15 08:23:47 | MIT License
play

ActionScript3 source code

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

package
{
//    import flash.display.Sprite;
    import flash.display.*;
    import flash.text.*;    
    import flash.events.Event;

    public class FlashTest extends Sprite
    {
        private var tfm:TextFormat = new TextFormat();
        private var tf:TextField = new TextField();        // 年月日用
        private var tf2:TextField = new TextField();       // 時分秒用
 
        public function FlashTest()
        {
            addEventListener(Event.ENTER_FRAME, now);
            var week:Array = ["SUN","MON","TUE","WED","THU","FRI","SAT"];
            
            function now(e:Event):void
            {
                tfm.size = 30;
                var n_date:Date = new Date();
    
                // 年月日、曜日
                tf.defaultTextFormat = tfm;
                tf.width = 250;
                tf.x = 100;
                tf.y = 200;
    
                var yy:String = n_date.getFullYear().toString();
                if (n_date.getMonth() + 1 < 10) {
                    var mm:String = "0" + (n_date.getMonth() + 1).toString();
                }
                else
                {
                    var mm:String = (n_date.getMonth() + 1).toString();
                }
                var dd:String = n_date.getDate().toString();
                var youbi:Number = n_date.getDay();
    
                tf.text = yy + "/" + mm + "/" + dd + "(" + week[youbi] + ")";
                addChild(tf);
    
                // 時間秒
                tf2.defaultTextFormat = tfm;
                tf2.width = 200;
                tf2.x = 140;
                tf2.y = 250;
    
                if (n_date.getHours() < 10)
                {
                    var hh:String = "0" + n_date.getHours().toString();
                }
                else
                {
                    var hh:String = n_date.getHours().toString();
                }
                if (n_date.getMinutes() < 10)
                {
                    var mi:String = "0" + n_date.getMinutes().toString();
                }
                else
                {
                    var mi:String = n_date.getMinutes().toString();
                }
                if (n_date.seconds < 10)
                {
                    var sec:String = "0" + n_date.getSeconds().toString();
                }
                else
                {
                    var sec:String = n_date.getSeconds().toString();
                }
    
                tf2.text = hh + " : " + mi + " : " + sec;
                addChild(tf2);
            }
        }
    }
}