我正在測驗相反的腳本作為倒數計時器,并且出現型別錯誤:
TypeError:錯誤 #1034:型別強制失敗:無法將 flash.events::Event@33d6b881f29 轉換為 flash.events.TimerEvent。
var goalTimerScore: int = Math.floor(Math.random() * 101) 20;
var Minutes:Number = Math.floor(Math.random() * 11);
var Seconds:Number = Math.floor(Math.random() * 60);
timerMin_txt.text = String(Seconds);
timerSec_txt.text = String(Minutes);
timerWatch.addEventListener(Event.ENTER_FRAME, countTimer);
timerWatch.play();
function countTimer(e:TimerEvent):void {
if (timerWatch.currentFrame == 61) {
Seconds--;
if (Seconds > 59) {
Seconds = 0;
timerSec_txt.text = "0" Seconds;
Minutes--;
if (Minutes > 10) {
timerMin_txt.text = "" Minutes;
} else {
timerMin_txt.text = "0" Minutes;
}
if (Minutes == 0 && Seconds == 0) {
timerWatch.removeEventListener(Event.ENTER_FRAME, countTimer);
timer.stop();
gotoAndPlay("gameover_Hidden3");
return;
}
}
else {
if (Seconds >= 10) {
timerSec_txt.text = "" Seconds;
} else {
timerSec_txt.text = "0" Seconds;
}
}
}
}
任何想法如何解決這個問題?
uj5u.com熱心網友回復:
你有錯誤的函式引數,它們應該是:
function countTimer(e:Event):void {
作為建議,在幀速率之外運行計時器可能會非常不一致,因為它依賴于恒定的幀速率。使用基于時間的方法可能更好。
您可以使用Timer該類作為基本方法。在倒計時的 asdocs 中有一個示例。
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Timer.html
uj5u.com熱心網友回復:
function countTimer(e: Event): void {
if (timerWatch.currentFrame == 61) {
Seconds--;
if (Seconds < 0) {
Minutes--;
Seconds = 59;
}
if (Minutes == 0 && Seconds == 0) {
timerWatch.removeEventListener(Event.ENTER_FRAME, countTimer);
timerWatch.stop();
gotoAndPlay("gameover_Hidden3");
return;
}
if (Minutes >= 1 && Seconds == 0) {
if (Minutes == 0) {
timerMin_txt.textColor = 0xFF0000;
timerSec_txt.textColor = 0xFF0000;
}
}
}
if (Seconds < 10) {
timerSec_txt.text = "0" Seconds;
} else {
timerSec_txt.text = "" Seconds;
}
if (Minutes < 10) {
timerMin_txt.text = "0" Minutes;
} else {
timerMin_txt.text = "" Minutes;
}
}
uj5u.com熱心網友回復:
計時器準確性的關鍵是stage.frameRate屬性。在不最大化的情況下,精度將是 60 Hz 的倍數。
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.getTimer;
import flash.utils.Timer;
stage.frameRate = 1000;
const t:Timer = new Timer(0);
t.addEventListener(TimerEvent.TIMER, t_h);
t.delay = 10000; //10 seconds
timestamp = getTimer();
t.start();
public function t_h(e:TimerEvent):void {
trace("countdown complete")
trace(getTimer() - timestamp)
t.stop();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/506672.html
標籤:actionscript-3 闪光 计时器 倒数
上一篇:問題>將“android.support.multidex.MultiDexApplication”更改為“androidx.multidex.MultiDexApplication”是否會導致
