Bunu nasıl geçersiz kılarsınız?
Date sınıfını, zamanı doğru olarak sayan bir komut dosyasında da kullanıyoruz.
- ilk karede bu kodu ekleyin
- minText, secText, MilText adında 3 Metin kutularının eklemek yeni AS3 belgesi ve bir düğme olarak adlandırılan start_btn oluşturun:
var STT: int; // başlangıç zamanını
var myTimer: Timer = new Timer (1 Timer) olarak izlemek için bu değişkeni kullanırız; // bu bizim zamanlayıcımız
var starttime:Date; // pretty obvious
var actualtime:Date; // pretty obvious
myTimer.addEventListener(TimerEvent.TIMER, stopWatch); // we start counting with this counter
start_btn.addEventListener(MouseEvent.CLICK, startClock); // add a button listener to start the timer
function startClock(event:MouseEvent):void
{
starttime = new Date(); // we get the moment of start
stt = int(starttime.valueOf().toString()); // convert this into a timestamp
myTimer.start(); // start the timer (actually counter)
}
function stopWatch(event:TimerEvent):void
{
actualtime = new Date(); // we get this particular moment
var att:int = int(actualtime.valueOf().toString()); // we convert it to a timestamp
// here is the magic
var sec:int = (Math.floor((att-stt)/1000)%100)%60; // we compute an absolute difference in seconds
var min:int = (Math.floor((att-stt)/1000)/60)%10; // we compute an absolute difference in minutes
var ms:int = (att-stt)%1000; // we compute an absolute difference in milliseconds
//we share the result on the screen
minText.text = String(min);
secText.text = String(sec);
milText.text = String(ms);
}
Neden zaman damgalarına ihtiyaç duyuyorsunuz ve Date sınıfının işlevlerini kullanmıyorsunuz?
Eğer iki olay arasındaki farkı saymak istiyorsanız muhtemelen bu kullanırsınız Çünkü: Başlangıç olay 57'th ikinci olur ve bitiş olay olur ise çok yanlış
endEvent.seconds - startEvent.seconds
17 saniye sonra, 20 yerine -40 saniye alırsınız.
'flash.utils.getTimer() Bu aldığım' Date' sınıf – BadFeelingAboutThis