我在AS3名称MainTimer.as
中创建计时器类,我main.as
使用MainTimer类来倒计时。当我将参数发送到MainTimer类时,它出现错误ArgumentError: Error #1063: Argument count mismatch on MainTimer(). Expected 2, got 0.
当MainTimer中的trace(startMin, startSec);
显示1 0
时。有人帮忙。
MainTimer.as
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class MainTimer extends MovieClip {
private var currentMin: int;
private var currentSec: int;
private var oneSecTimer: Timer = new Timer(1000, 1);
public var timerHasStopped: Boolean = false;
public function MainTimer(startMin: int, startSec: int) {
trace(startMin, startSec);
currentMin = startMin;
currentSec = startSec;
minBox.text = String(currentMin);
secBox.text = String(currentSec);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
oneSecTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
oneSecTimer.start();
// trace(currentMin, currentSec);
}
private function onTimerComplete(event: TimerEvent): void {
minBox.text = String(currentMin);
secBox.text = String(currentSec);
//trace(secBox.text);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
currentSec = currentSec - 1;
if (currentSec <= -1) {
currentSec = 59;
currentMin -= 1;
//trace(minBox.text);
}
if (currentMin <= -1) {
timerHasStopped = true;
//resetTimer();
} else {
oneSecTimer.start();
}
}
public function resetTimer(): void {
currentMin = 0;
currentSec = 20;
minBox.text = String(currentMin);
secBox.text = String(currentSec);
if (currentSec < 10) {
secBox.text = "0" + String(currentSec);
}
timerHasStopped = false;
oneSecTimer.start();
}
public function increaseTime(): void {
currentSec += 20;
}
}}
main.as
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import MainTimer;
public class main extends MovieClip {
private var startMin: int = 1;
private var startSec: int = 0;
private var gameTimer: MainTimer = new MainTimer(startMin, startSec);
public function main() {
addChild(gameTimer);
}
}}
答案 0 :(得分:3)
我认为您已在舞台中手动插入MainTimer
影片剪辑的实例。
为避免#1063
错误,您必须删除该实例,或者只是在MainTimer
类构造函数中定义默认值:
// ...
public function MainTimer(startMin:int = 1, startSec:int = 0)
{
// ...
}
// ...
希望可以提供帮助。
答案 1 :(得分:0)
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
import flash.utils.Timer;
import MainTimer;
public class main extends MovieClip {
private var startMin: int = 1;
private var startSec: int = 0;
private var gameTimer: MainTimer;
public function main() {
gameTimer = new MainTimer(startMin, startSec);
addChild(gameTimer);
}}}
尝试这样做应该有效:)