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: Due3.Screensaver Clock Modoki

http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* これを作ってみようとしているところ
// forked from ahchang's Due3.Screensaver Clock Modoki
// forked from ahchang's forked from: clock01
// forked from ll_koba_ll's clock01
/*
* http://www.apple.com/downloads/macosx/icons_screensavers/due3screensaverclock.html
* これを作ってみようとしているところ
*/
package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.filters.*;
    import flash.utils.*;
    import caurina.transitions.Tweener;
    import flash.text.*;
    
    [SWF(width="465",height="465",frameRate="60",backgroundColor="0x222222")]
    
    public class Clock01 extends Sprite
    {
        private var secondHand:Sprite;
        private var minuteHand:Sprite;
        private var hourHand:Sprite;
        private var center:Point;
        private var tf:TextField;
        
        public function Clock01()
        {
            //init();
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            // mac firefoxでstageWidthが取得できないので1フレ遅らせる
            addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                removeEventListener(Event.ENTER_FRAME, arguments.callee);
                center = new Point();
                center.x = 200;
                center.y = 320;
                createSecondHand();
                createMinuteHand();
                createHourHand();
                initAnime();
            })
        }
        
        private function initAnime():void
        {
            var d:Date = new Date();
            var s:int = d.getSeconds();
            var m:int = d.getMinutes();
            var h:int = d.getHours();
            
            Tweener.addTween(secondHand,{rotation:getRotation(s, 60), time:1, transition:"easeOutBounce"});
            Tweener.addTween(minuteHand,{rotation:getRotation(m, 60), time:1, transition:"easeOutBounce"});        
            Tweener.addTween(hourHand, {rotation:getRotation(h, 12)+360/12/60*m, time:1, transition:"easeOutBounce"});
            
            var year:int = d.getFullYear();
            var month:int = d.getMonth();
            var date:int = d.getDate();
            var week:int = d.getDay();
            
            createTextField();
            start();
        }

        private function start():void
        {
            var t:Timer = new Timer(1000, 0);
            t.addEventListener(TimerEvent.TIMER, timer);
            t.start();
        }
        
        private function createTextField():void
        {
            var format:TextFormat = new TextFormat();
            format.size = 20;
            format.font = "Helvetica";
            
            var tf1:TextField = new TextField();
            tf1.textColor = 0xffffff;
            tf1.defaultTextFormat = format;
            tf1.autoSize = TextFieldAutoSize.LEFT;
            tf1.x = 20;
            tf1.y = 385;
            
            var tf2:TextField = new TextField();
            tf2.textColor = 0xafeeee;
            tf2.defaultTextFormat = format;
            tf2.autoSize = TextFieldAutoSize.LEFT;
            tf2.x = 20;
            tf2.y = 405;
            
            var tf3:TextField = new TextField();
            tf3.textColor = 0xffffff;
            tf3.defaultTextFormat = format;
            tf3.autoSize = TextFieldAutoSize.LEFT;
            tf3.x = 20;
            tf3.y = 425;
            
            var week:Array = ["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURSDAY"];
            var month:Array = ["JANUARY","FEBRUARY","MARCH","APRIL","MAY","JUNE","JULY","AUGUST","SEPTEMBER","OCTOBER","NOVEMBER","DECEMBER"]
            
            var d:Date = new Date();
            var year:int = d.getFullYear();
            var monthIndex:int = d.getMonth();
            var day:int = d.getDate();
            var weekIndex:int = d.getDay();
            var s:int = d.getSeconds();
            var m:int = d.getMinutes();
            var h:int = d.getHours();
            
            tf1.text = week[weekIndex] 
            tf2.text = month[monthIndex] + " " + day + ", " + year;
            tf3.text = h + ":" + m + " / " + s;
            
            addChild(tf1);
            addChild(tf2);
            addChild(tf3);
        }

        private function createSecondHand():void
        {
            secondHand = new Sprite;
            var g:Graphics = secondHand.graphics;
            
            g.beginFill(0xafeeee);
            g.drawRect(0, -460, 1, 450);
            g.endFill();
                        
            addChild(secondHand);
            secondHand.x = center.x;
            secondHand.y = center.y;
        }

        private function createMinuteHand():void
        {
            minuteHand= new Sprite;
            var g:Graphics = minuteHand.graphics;
            
            g.beginFill(0x444444);            
            g.drawRect(0, -460, 1, 450);            
            g.endFill();
            
            addChild(minuteHand);
            minuteHand.x = center.x;
            minuteHand.y = center.y;
        }

        private function createHourHand():void
        {
            hourHand = new Sprite;
            var g:Graphics = hourHand.graphics;
            
            g.beginFill(0x444444);
            g.drawRect(0, -430, 1, 450);
            g.endFill();
            
            addChild(hourHand);
            hourHand.x = center.x;
            hourHand.y = center.y;
        }       

        private function timer(e:TimerEvent = null):void
        {
            var d:Date = new Date();
            var s:int = d.getSeconds();
            var m:int = d.getMinutes();
            var h:int = d.getHours();
                                   
            var sr:Number = getRotation(s, 60);
            Tweener.addTween(secondHand, { rotation:sr, time:1, transition:"easeOutBounce"});

            if (s == 0)
            {
                var mr:Number = getRotation(m,60);
                Tweener.addTween(minuteHand, { rotation:mr+360, time:2});
                
                var hr:Number = 360/12*h + (360/12/60*m);
                hourHand.rotation = hr;
            }
        }

        private function getRotation(val:int, bunkatsu:int = 60):Number
        {
            return (360/bunkatsu*val <= 186)? 360/bunkatsu*val : -(360 - 360/bunkatsu*val);
        }
    }
}