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

clock(practice)

(☝ ՞ਊ ՞)☝ 時計です
Get Adobe Flash player
by about 12 Feb 2013
    Embed
/**
 * Copyright about ( http://wonderfl.net/user/about )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2wrP
 */

package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BevelFilter;
    import flash.filters.DropShadowFilter;
    import flash.geom.Matrix;
    import flash.sampler.StackFrame;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    import avmplus.FLASH10_FLAGS;
    
    [SWF(width="465", height="465")]
    public class clock extends Sprite
    {
        private const WEEK:Array = ["日", "月", "火" , "水", "木", "金" , "土"];
        private var background:Sprite = new Sprite;
        private var top_num:Vector.<number_char> = new Vector.<number_char>;
        private var top_num_list:Sprite = new Sprite();
        private var bottom_num:Vector.<number_char> = new Vector.<number_char>;
        private var bottom_num_list:Sprite = new Sprite();
        private var left_num:Vector.<number_char> = new Vector.<number_char>;
        private var left_num_list:Sprite = new Sprite();
        private var right_num:Vector.<number_char> = new Vector.<number_char>;
        private var right_num_list:Sprite = new Sprite();
        private var center_clock:Sprite = new Sprite();
        private var center_time:Vector.<TextField> = new Vector.<TextField>;
        private var hn:Sprite = new Sprite(); //長針
        private var mn:Sprite = new Sprite(); //短針
        private var sn:Sprite = new Sprite(); //秒針
        private var tmp:String;
        private var tf_second:TextField = new TextField();
        private var tf_min:TextField = new TextField();
        private var tf_hour:TextField = new TextField();
        private var tf_year:TextField = new TextField();
        private var tf_month:TextField = new TextField();
        private var tf_day:TextField = new TextField();
        private var flag:Boolean=false;
        
        public function clock()
        {
            addEventListener(Event.ENTER_FRAME,onEnterFrame);    
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(stage.stageWidth,stage.stageHeight,0,0,0);
            //background
            background.graphics.beginGradientFill("radial",[0xfff,0],[1.0,1.0],[0,255],matrix);
            background.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
            background.graphics.endFill();
            addChild(background);
            
            //analog
            //針の設定
            sn = new Sprite();
            sn.graphics.beginFill(0x777777);
            sn.graphics.drawRect(0, -1, 150, 2);
            sn.graphics.endFill();
            sn.filters = [new DropShadowFilter(0, 60, 0x696969)];
            sn.x = sn.y = 232;
            addChild(sn);
            
            mn = new Sprite();
            mn.graphics.beginFill(0x393939);
            mn.graphics.drawRect(0, -3, 120, 3);
            mn.graphics.endFill();
            mn.filters = [new DropShadowFilter(4)];
            mn.x = mn.y = 232;
            addChild(mn);
            
            hn = new Sprite();
            hn.graphics.beginFill(0x393939);
            hn.graphics.drawRect(0, -3, 120, 3);
            hn.graphics.endFill();
            hn.filters = [new DropShadowFilter(0)];
            hn.x = hn.y = 232;
            addChild(hn);
            
            //中心点
            var analog_clock_point:Sprite = new Sprite();
            analog_clock_point.graphics.lineStyle(3,0x00ff00);
            analog_clock_point.graphics.beginFill(0xffffff);
            analog_clock_point.graphics.drawCircle(stage.stageWidth/2,stage.stageHeight/2,5);
            analog_clock_point.graphics.endFill();
            addChild(analog_clock_point);
            
            //top_number_list
            addChild(top_num_list);
            make_list_1(top_num_list,top_num,55,10);
            //bottom_number_list
            addChild(bottom_num_list);
            make_list_1(bottom_num_list,bottom_num,55,400);
            //left_number_list
            addChild(left_num_list);
            make_list_2(left_num_list,left_num,10,55);
            //right_number_list
            addChild(right_num_list);
            make_list_2(right_num_list,right_num,425,55);
            //center_clock
            addChild(center_clock);
            for(var i:int=0;i<10;i++){
                top_num[i].alpha = 0;
            }
        }
        
        private function onEnterFrame(e:Event):void{
            var date:Date = new Date();            
            var h:Number = date.getHours();
            var minute:Number = date.getMinutes();
            var second:Number = date.getSeconds();
            var month:Number = date.getMonth();
            var day:Number = date.getDate();
            // 一桁の時は0埋め
            var hStr:String = h < 10 ? "0" + h.toString() : h.toString();            
            var mStr:String = minute < 10 ? "0" + minute.toString() : minute.toString();
            var sStr:String = second < 10 ? "0" + second.toString() : second.toString();
            var dStr:String = day < 10 ?  "0" + day.toString() : day.toString();
            var mmStr:String = month < 10 ?  "0" + month.toString() : month.toString();            
            //秒のアニメーション
            var sa:Array = sStr.split("");
            //一の位
            if(tmp == sa[1])fadeOut(top_num[(int)(sa[1])]);
            else top_num[(int)(sa[1])].alpha = 1;
            
            if(tmp != sa[1]){
                tmp = sa[1];
                fadeIn(top_num[(int)(sa[1])]);
                var s1:int = (sa[1] == "0" ? s1 = 9 : s1 = (int)(sa[1])-1); 
                top_num[s1].alpha = 0;
            }
            tmp = sa[1];
            //十の位
            var s:int = (sa[0] == "0" ? s = 5 : s = (int)(sa[0])-1); 
            fadeOut(right_num[(int)(sa[0])]);
            fadeIn(right_num[s]);
            
            //分のアニメーション
            var sa2:Array = mStr.split("");
            //一の位
            var s1:int = (sa2[1] == "0" ? s1 = 9 : s1 = (int)(sa2[1])-1); 
            fadeOut(bottom_num[(int)(sa2[1])]);
            fadeIn(bottom_num[s1]);
            //十の位
            var s2:int = (sa2[0] == "0" ? s2 = 5 : s2 = (int)(sa2[0])-1); 
            fadeOut(left_num[(int)(sa2[0])]);
            fadeIn(left_num[s2]);
            
            //center_clock
            //seconds
            tf_second.defaultTextFormat = new TextFormat("",80,0x00ffff,true);
            tf_second.text = sStr;
            tf_second.x = 300;
            tf_second.y = 150;
            center_clock.addChild(tf_second);
            //miniutes
            tf_min.defaultTextFormat = new TextFormat("",80,0x32cd32,true);
            tf_min.text = mStr;
            tf_min.x = stage.stageWidth/2-45;
            tf_min.y = 150;
            center_clock.addChild(tf_min);
            //hours
            tf_hour.defaultTextFormat = new TextFormat("",80,0xffd700,true);
            tf_hour.text = hStr;
            tf_hour.x = 70;
            tf_hour.y = 150;
            center_clock.addChild(tf_hour);
            //year
            tf_year.defaultTextFormat = new TextFormat("",40,0xfffafa,true);
            tf_year.text = (String)(date.getFullYear());
            tf_year.x = 100;
            tf_year.y = 250;
            center_clock.addChild(tf_year);
            //month
            tf_month.defaultTextFormat = new TextFormat("",40,0xfffafa,true);
            tf_month.text = mmStr;
            tf_month.x = 210;
            tf_month.y = 250;
            center_clock.addChild(tf_month);
            //day
            tf_day.defaultTextFormat = new TextFormat("",40,0xfffafa,true);
            tf_day.text = dStr;
            tf_day.x = 280;
            tf_day.y = 250;
            center_clock.addChild(tf_day);
            
            //長針、短針
            sn.rotation = (date.seconds + date.milliseconds / 1000) * 6 - 90;
            mn.rotation = (date.minutes + date.seconds / 60) * 6 - 90;
            hn.rotation = (date.hours + date.minutes / 60) * 30 - 90;
        }
        
        private function fadeIn(num:number_char):void{
            if(num.alpha < 1){
                num.alpha += 0.05;
                fadeIn;
            }
        }
        
        private function fadeOut(num:number_char):void{
            if(num.alpha >= 0){
                num.alpha -= 0.05;
                fadeOut;
            }
        }
        
        //  top and bottom
        private function make_list_1(ins:Sprite,num_name:Vector.<number_char>,first_x:Number,first_y:Number):void{
            ins.addChild(num_name[0] = new number_char("0",0xff4500,60,first_x,first_y));
            ins.addChild(num_name[1] = new number_char("1",0xff8c00,60,first_x+35,first_y));
            ins.addChild(num_name[2] = new number_char("2",0x7cfc00,60,first_x+70,first_y));
            ins.addChild(num_name[3] = new number_char("3",0x00fa9a,60,first_x+105,first_y));
            ins.addChild(num_name[4] = new number_char("4",0x00ff7f,60,first_x+140,first_y));
            ins.addChild(num_name[5] = new number_char("5",0x00bfff,60,first_x+175,first_y));            
            ins.addChild(num_name[6] = new number_char("6",0x1e90ff,60,first_x+210,first_y));
            ins.addChild(num_name[7] = new number_char("7",0x00ff7f,60,first_x+245,first_y));
            ins.addChild(num_name[8] = new number_char("8",0xff00ff,60,first_x+280,first_y));
            ins.addChild(num_name[9] = new number_char("9",0xff69b4,60,first_x+315,first_y));
        }
        // left and right
        private function make_list_2(ins:Sprite,num_name:Vector.<number_char>,first_x:Number,first_y:Number):void{
            ins.addChild(num_name[0] = new number_char("0",0xff4500,40,first_x,first_y));
            ins.addChild(num_name[1] = new number_char("1",0xff8c00,40,first_x,first_y+35));
            ins.addChild(num_name[2] = new number_char("2",0x7cfc00,40,first_x,first_y+70));
            ins.addChild(num_name[3] = new number_char("3",0x00fa9a,40,first_x,first_y+105));
            ins.addChild(num_name[4] = new number_char("4",0x00ff7f,40,first_x,first_y+140));
            ins.addChild(num_name[5] = new number_char("5",0x00bfff,40,first_x,first_y+175));            
            ins.addChild(num_name[6] = new number_char("6",0x1e90ff,40,first_x,first_y+210));
            ins.addChild(num_name[7] = new number_char("7",0x00ff7f,40,first_x,first_y+245));
            ins.addChild(num_name[8] = new number_char("8",0xff00ff,40,first_x,first_y+280));
            ins.addChild(num_name[9] = new number_char("9",0xff69b4,40,first_x,first_y+315));
        }
    }
}

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;

class number_char extends Sprite{
    private var n:TextField = new TextField();
    public function number_char(c:String,color:uint,thick:Number,dx:Number,dy:Number){
        n.defaultTextFormat = new TextFormat("",thick,color, true);
        n.text = c;
        n.x = dx;
        n.y = dy;
        addChild(n);
    }
}