国庆60周年倒计时牌(4 位领导批示)
- 2009-09-2
- 分类:ActionScript
- 作者:银子
- 1,549 位领导视察
迎接祖国60周年华诞..抽空写了个倒计时牌(Javascript版本倒计时. 为奥运会写的)
DEMO: http://www.zdyi.com/flash/countdown.swf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | package { import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFormat; import flash.text.TextFieldAutoSize; import flash.events.TimerEvent; import flash.utils.Timer; public class CountDown extends Sprite { private var box:TextField = new TextField(); private var title:TextField = new TextField(); var textF:TextFormat = new TextFormat(); private var timeDiff:String; private var beginTime:Date; private var endTime:Date = new Date(2009, 9, 1, 00); /** * 构造函数 * */ public function CountDown() { textF.font = "微软雅黑"; textF.size = 12; textF.color = 0x333333; box.x = 76; box.y = 26; box.background = true; box.backgroundColor = 0xFFFFFF; box.defaultTextFormat = textF; box.autoSize = TextFieldAutoSize.LEFT; beginTime = new Date(); timeDiff = getTimeDiff(); box.text = timeDiff; title.x = 96; title.y = 2; title.background = true; title.backgroundColor = 0xFFFFFF; title.defaultTextFormat = textF; title.autoSize = TextFieldAutoSize.LEFT; title.text = "距60周年国庆还有:"; addChild(box); addChild(title); var timer:Timer = new Timer(1000); timer.addEventListener(TimerEvent.TIMER, timerHandler); timer.start(); } /** * 事件函数 一秒钟刷新一次 * */ private function timerHandler(event):void { beginTime = new Date(); timeDiff = getTimeDiff(); box.text = timeDiff; } /** * 获取时间差 * */ private function getTimeDiff():String { var diff:Number = Math.round((endTime.getTime()-beginTime.getTime())/1000); if (diff >= 0) { var d:uint = Math.floor(diff/60/60/24); diff %= 60*60*24; var h:uint = Math.floor(diff/60/60); diff %= 60*60; var m:uint = Math.floor(diff/60); var s:uint = diff % 60; } return d + " 天 " + fixZero(h) + " 小时 " + fixZero(m) + " 分 " + fixZero(s) + " 秒"; } /** * 时间补零 * */ private function fixZero(num:uint):String { return (num < 10) ? '0' + String(num) : String(num); } } } |
相关文章
NOTE:本博内容大部分为原创,转载请注明出处。
永久链接:http://www.zdyi.com/count-down/444


























最近刚好要用到这个代码.借鉴了:)
@zwwooooo 要合谐要有爱..![[face3]](http://www.zdyi.com/wp-includes/images/face/3.gif)
考试希望快点过完国庆,这网络现在都墙的像啥了?