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 + Carender

大学の課題用。

・アナログ時計
・日付表示
・時間帯によって背景が変化

背景表示と時計の針の更新用に
タイマーを二つ用意。
Get Adobe Flash player
by Yui.Ohsaki 25 Jan 2012
/**
 * Copyright Yui.Ohsaki ( http://wonderfl.net/user/Yui.Ohsaki )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uydJ
 */

package {
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.DisplayObject;

   
  
    public class FlashTest extends Sprite {
        public var g:Sprite = new Sprite(); // 針(三本)
        public var first:Boolean; //呼び出しフラグ(初回)
       public var date:Date = new Date;
       public var ih:int = date.getHours();
       
       
 
        // 外部の画像ファイルを使用する
        public var imgLoader:Loader = new Loader();

                                    
        public function FlashTest() {
            // write as3 code here..
        
        var img:int;

       if( ih >= 6 && ih < 12 ){
           img = 0;
       }else if(ih  >= 12 && ih < 18){
           img = 1;
       }else if(ih >= 18 && ih <= 24 || ih > 0 && ih < 6){
           img = 2;
       }





            var urlReq:URLRequest = new URLRequest( "http://www.cc.matsuyama-u.ac.jp/~12090639/image/" + img +".png" );
            imgLoader.load( urlReq );
            imgLoader.x = 0;
            imgLoader.y = 0;
            imgLoader.alpha = 0 ;
            addChild( imgLoader ); 
           


            var s:Sprite = new Sprite; //時計盤
            var c:Sprite = new Sprite; //カレンダー
        
            //時計盤設定
            s.graphics.beginFill( 0x000000, 0.6);
            s.graphics.lineStyle( 1, 0xffffff, 1.0);
            s.graphics.drawCircle( 145, 225, 125);

            s.graphics.beginFill( 0xffffff, 1.0);
            s.graphics.lineStyle( 1, 0xffffff, 1.0);
            s.graphics.drawCircle( 145, 225, 3);
        
            c.graphics.beginFill( 0x000000, 0.6);
            c.graphics.lineStyle( 1, 0xffffff, 1.0);
            c.graphics.drawCircle( 265 , 100, 60);
            
            c.graphics.beginFill( 0xffffff, 1.0);
            c.graphics.lineStyle( 1, 0xffffff, 1.0);
            c.graphics.drawCircle( 265 , 100, 5);

        
        //目盛設定
            var i:int;
            for( i = 0; i < 60; i++){
                var theta:Number = 2 * Math.PI * i/60;
                s.graphics.moveTo( 145 + 120 * Math.cos(theta), 225 + 120 * Math.sin(theta));
           
               if(i % 15 == 0){
                   s.graphics.lineStyle( 5, 0xffffff , 1.0);
                   s.graphics.lineTo( 145 + 115 * Math.cos(theta), 225 + 115 * Math.sin(theta));                   
               }else if(i % 5 == 0 ){
                   s.graphics.lineStyle( 2, 0xffffff , 1.0);
                   s.graphics.lineTo( 145 + 118 * Math.cos(theta), 225 + 118 * Math.sin(theta));
               }else{
                   s.graphics.lineStyle( 1, 0xffffff , 1.0);
                   s.graphics.lineTo( 145 + 119 * Math.cos(theta), 225 + 119 * Math.sin(theta));
               }
            }


           for( i = 0; i < 60; i++){
                theta = 2 * Math.PI * i/60;
                c.graphics.moveTo( 360 + 70 * Math.cos(theta), 80 + 70 * Math.sin(theta));

              
               if(i % 6 == 0 ){
                   c.graphics.moveTo( 265 + 50 * Math.cos(theta), 100 + 50 * Math.sin(theta));
                   c.graphics.lineStyle( 2, 0xffffff , 1.0);
                   c.graphics.lineTo( 265 + 51 * Math.cos(theta), 100 + 51 * Math.sin(theta));
               }
            }
   
            addChild( c );
            addChild( s );
            


        
            //
            var nowcal:Date = new Date;
            
            var dayOfWeek_array:Array = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
            var calDay:String = dayOfWeek_array[nowcal.getDay()];
            
            var Months_array:Array = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" );
            var calMonth:String = Months_array[nowcal.getMonth()];
            
            var calYear:int = nowcal.getFullYear();
            var calDate:int = nowcal.getDate();
            
             var caltxt1:TextField = new TextField();
             caltxt1.x = 215;
             caltxt1.y = 65;
             caltxt1.autoSize = TextFieldAutoSize.CENTER;
             caltxt1.textColor = 0xcccccc;
             caltxt1.text = "" + calYear + "" ;
             
             var caltxt2:TextField = new TextField();
             caltxt2.x = 220;
             caltxt2.y = 115;
             caltxt2.autoSize = TextFieldAutoSize.CENTER;
             caltxt2.textColor = 0xcccccc;
             caltxt2.text = calMonth + " . " + calDate + "( "+ calDay + " ) ";



             addChild(caltxt1);
             addChild(caltxt2);
            
  
            first = true;
        
            //タイマー設定(時計)
            var timer:Timer = new Timer( 1000 );
            timer.addEventListener( TimerEvent.TIMER, moveSecond );            
            timer.start();
            
            //タイマー設定(背景)
            var timerb:Timer = new Timer( 30 );
            timerb.addEventListener( TimerEvent.TIMER, backGroundFade ); 
            timerb.start();
        
        }
        
        public function backGroundFade( event:TimerEvent):void{
            

            
                 if(imgLoader.alpha < 1){
                     imgLoader.alpha += 1 / 10;
                 }
        }
        
        
        
        public function moveSecond( event:TimerEvent):void{
            

       

            

         
            
            //日時
            var now:Date = new Date();
            
            var h:int = now.getHours();
            var m:int = now.getMinutes();
            var s:int = now.getSeconds();
            
            //初回呼び出し時はリムーブしない
            if(first){
                first = false;
            }else{
                removeChild( g );
            }

            g.graphics.clear();
      
        
            var theta:Number;
        
            g.graphics.lineStyle( 1 , 0xfffffff, 1.0);
            theta = 2 * Math.PI * s / 60 - Math.PI / 2;
            g.graphics.moveTo( 145, 225);
            g.graphics.lineTo( 145 + 110 * Math.cos(theta) , 225 + 110 * Math.sin(theta));
              
            g.graphics.lineStyle( 2 , 0xffffff, 1.0);
            theta = 2 * Math.PI *( s + m / 60) - Math.PI / 2;
            g.graphics.moveTo( 145, 225);
            g.graphics.lineTo( 145 + 100 * Math.cos(theta) , 225 + 100 * Math.sin(theta));

            g.graphics.lineStyle( 5 , 0xffffff, 1.0);
            theta = 2 * Math.PI * ( h + m / 60 ) / 12 - Math.PI / 2;
            g.graphics.moveTo( 145, 225);
            g.graphics.lineTo( 145 + 60 * Math.cos(theta) , 225 + 60 * Math.sin(theta));
       
        
            addChild( g ) ;

        }
        
 
    }
}