2 つのカウントダウン タイマーを備えた単純な Web サイトを構築しています。問題は、それらが同期しないことです。Web ページが読み込まれると、一方のタイマーが他方よりも著しく進んでいます。使用した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>
フラッシュ vid では 2 つのレイヤーを使用しました。背景要素 (タイマーの動的テキストを含む) を含むものと、次のコードのみを含むもの:
止まる();
var countDownTimer:Timer = new Timer(10);
countDownTimer.addEventListener(TimerEvent.TIMER, updateTimer);
countDownTimer.start();
関数 updateTimer(Event:TimerEvent):void{
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...";
}
}