国庆60周年倒计时牌(4 位领导批示)

迎接祖国60周年华诞..抽空写了个倒计时牌(Javascript版本倒计时. 为奥运会写的)

DEMO: http://www.zdyi.com/flash/countdown.swf

?View Code ACTIONSCRIPT
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);
		}
	}
}

相关文章

分享到新浪微博 推荐到豆瓣 分享到 Google Reader 加入Google书签 嘀咕一下 分享到饭否 分享到做啥 分享到叽歪 分享到鲜果 加入QQ书签 加入百度搜藏 加入雅虎书签 分享到垦一垦

  1. 4
    的哥

    最近刚好要用到这个代码.借鉴了:)

  2. 3
    漠岚

    [face5]学习了 谢谢

  3. 2
    银子

    @zwwooooo 要合谐要有爱.. [face3]

  4. 1
    zwwooooo

    考试希望快点过完国庆,这网络现在都墙的像啥了?

请领导指示

验证码 (必须)

Additional comments powered by BackType

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志