我正在建立一个带有两个倒数计时器的简单网站。问题是它们不同步。当网页加载时,一个计时器明显领先于另一个。这是使用的html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css" media="screen">
#flashContent { width:100%; height:100%; }
</style>
</head>
<body >
<div id="flashContent" align="center" >
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" id="Timer" align="middle">
<param name="movie" value="Timer.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Timer.swf" width="400" height="250">
<param name="movie" value="Timer.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="250" id="Timer" align="middle">
<param name="movie" value="Timer.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="Timer.swf" width="400" height="250">
<param name="movie" value="Timer.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="play" value="true" />
<param name="loop" value="true" />
<param name="wmode" value="transparent" />
<param name="scale" value="showall" />
<param name="menu" value="true" />
<param name="devicefont" value="false" />
<param name="salign" value="" />
<param name="allowScriptAccess" value="sameDomain" />
<!--<![endif]-->
<a href="http://www.adobe.com/go/getflash">
<img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
</a>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
</div>
</body>
我在 Flash vid 中使用了两层。一个有背景元素(包括计时器的动态文本),一个只有这段代码:
停止();
var countDownTimer:Timer = new Timer(10);
countDownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countDownTimer.start();
函数更新定时器(事件:定时器事件):无效{
var today:Date = new Date();
var destination:Date = new Date(2012,10,9,18,0,0,0);
if(destination.getTime()-today.getTime() < 0 ){
Time_txt.text = "00:00:00:00";
Title_txt.text = "It's Double Time!";
}else{
var daysLeft = Math.floor((destination.getTime()-today.getTime())/(1000*60*60*24));
var hoursLeft = Math.floor(((destination.getTime()-today.getTime())/(1000*60*60))-daysLeft*24);
var minutesLeft = Math.floor(((destination.getTime()-today.getTime())/(1000*60))-daysLeft*24*60-hoursLeft*60);
var secondsLeft = Math.floor(((destination.getTime()-today.getTime())/(1000))-daysLeft*24*60*60-hoursLeft*60*60-minutesLeft*60);
var days:String = new String(daysLeft);
var hours:String = new String(hoursLeft);
var minutes:String = new String(minutesLeft);
var seconds:String = new String(secondsLeft);
if(days.length < 2) days = "0" + days;
if(hours.length < 2) hours = "0" + hours;
if(minutes.length < 2) minutes = "0" + minutes;
if(seconds.length < 2) seconds = "0" + seconds;
var time:String = days +":"+ hours+":"+minutes+":"+seconds;
Time_txt.text = time;
Title_txt.text = "Jazz awaits in...";
}
}