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

clock01

Get Adobe Flash player
by ll_koba_ll 28 Dec 2008
package {
    
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.filters.*;
    import flash.utils.*;
    import caurina.transitions.Tweener;
    
    public class Clock01 extends Sprite
    {

        private var secondHand:Sprite;
        private var minuteHand:Sprite;
        private var hourHand:Sprite;
        private var center:Point;
        
        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 = stage.stageWidth/2;
                center.y = stage.stageHeight/2;
                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});
            Tweener.addTween(minuteHand,{rotation:getRotation(m, 60), time:1});            
            Tweener.addTween(hourHand, {rotation:getRotation(h, 12)+360/12/60*m, time:1});
            
            start();
        }

        private function start():void
        {

            var t:Timer = new Timer(1000, 0);
            t.addEventListener(TimerEvent.TIMER, timer);
            t.start();
            
        }

        private function createSecondHand():void
        {
            secondHand = new Sprite;
            var g:Graphics = secondHand.graphics;

            // second
            g.lineStyle(2, 0x00bbff)
            g.beginFill(0x000000);
            g.drawCircle(0,0, 100);
            g.endFill();
            g.lineStyle(0,0xffffff,0);
            g.beginFill(0x00bbff);
            g.drawRect(-2, -99, 4,30);
            g.endFill();
            
            addChild(secondHand);
            secondHand.x = center.x;
            secondHand.y = center.y;

        }

        private function createMinuteHand():void
        {
            minuteHand= new Sprite;
            var g:Graphics = minuteHand.graphics;

            // second
            g.beginFill(0x131313);
            g.drawCircle(0,0, 70);
            g.endFill();
            g.beginFill(0x00bbff);
            g.drawRect(-2, -69, 4,30);
            g.endFill();
            
            addChild(minuteHand);
            minuteHand.x = center.x;
            minuteHand.y = center.y;

        }

        private function createHourHand():void
        {
            hourHand= new Sprite;
            var g:Graphics = hourHand.graphics;

            // second
            g.beginFill(0x171717);
            g.drawCircle(0,0, 40);
            g.endFill();
            g.beginFill(0x00bbff);
            g.drawRect(-2, -39, 4,30);
            g.endFill();
            
            addChild(hourHand);
            hourHand.x = center.x;
            hourHand.y = center.y;

            var d:Date = new Date();
            var h:Number = d.getHours();
            var m:Number = d.getMinutes();
            
        }

        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});

            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);
        }
    }
}