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

アナログテレビ放送終了まで、あと・・・ on 2010-2-5

Get Adobe Flash player
by komatsu 09 Jul 2010
/**
 * Copyright komatsu ( http://wonderfl.net/user/komatsu )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/deG0
 */

package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextFormat;
    import flash.text.TextField;
    
    [SWF(backgroundColor="#000000", frameRate=30)]
    
    public class CountDown extends Sprite {
            private const STW:uint = stage.stageWidth;
        private const STH:uint = stage.stageHeight;
        private var tf:TextField;
        private var fmt:TextFormat;
        private var remain:Remaining;
        
        public function CountDown() {
            
            tf = new TextField();
            tf.x = 0;
            tf.width = STW;
            tf.y = (STH - tf.height)/2;
            tf.selectable = false;
            addChild(tf);
            
            fmt = new TextFormat()
            fmt.size = 24;
            fmt.align = "center";
            fmt.color = 0xCCCCCC;
           
           
               //アナログテレビ放送終了は 2011年7月24日まで
               var tYear:uint = 2011;
               var tMonth:uint = 7;
               var tDay:uint = 24;
               var tHours:uint = 0;
            remain = new Remaining(new Date(tYear,tMonth-1,tDay,tHours));
            
            addEventListener(Event.ENTER_FRAME ,  onEnterFrame);
        }
        
        
        private function onEnterFrame(evtObj:Event):void{
            var milisec:String = String(remain.getRemainTime());
            milisec = milisec.substr(milisec.length-3,3);
            var sec:String = add0(remain.getRemainSeconds() , 2);
            var min:String = add0(remain.getRemainMinutes() , 2);
            var hour:String = add0(remain.getRemainHours() , 2);
            var day:String = String(remain.getRemainDays());
            var str:String = "アナログテレビ放送終了まで、あと\n"+day+" 日と   " +  hour + ":" + min + ":" + sec + ":" + milisec;
            tf.text = str;
            tf.setTextFormat(fmt);
        }
        
        
        private function add0(num:uint , keta:uint):String{
            var rStr:String=String(num);
            var strCnt:uint = keta - String(num).length;
            if(strCnt > 0){
                for(var i:uint=0;i<strCnt;i++){
                    rStr = "0"+rStr;
                }
            }
            return rStr;
        }
    }
}
class Remaining{    
    private var tDate:Date;
    private var target_sec:Number;

    public function Remaining(targetDate:Date){
        tDate = targetDate;
        target_sec = tDate.getTime();
    }
    public function getRemainTime():Number{
        var now_date:Date = new Date();
        var now_sec:Number = now_date.getTime();
        var pastMillisec:Number = target_sec - now_sec;
        return pastMillisec;
    }
    public function getRemainSeconds():Number{
        var now_date:Date = new Date();
        var now_sec:Number = now_date.getTime();
        var pastMillisec:Number = target_sec - now_sec;
        return Math.floor(pastMillisec/1000)%60;
    }
    public function getRemainMinutes():Number{
        var now_date:Date = new Date();
        var now_sec:Number = now_date.getTime();
        var pastMillisec:Number = target_sec - now_sec;
        return Math.floor(pastMillisec/1000/60)%60;
    }
    public function getRemainHours():Number{
        var now_date:Date = new Date();
        var now_sec:Number = now_date.getTime();
        var pastMillisec:Number = target_sec - now_sec;
        return Math.floor(pastMillisec/1000/60/60)%24;
    }
    public function getRemainDays():Number{
        var now_date:Date = new Date();
        var now_sec:Number = now_date.getTime();
        var pastMillisec:Number = target_sec - now_sec;
        return Math.floor(pastMillisec/1000/60/60/24);
    }
}