Flash Actionscript 2.0计时器

Flash Actionscript 2.0计时器,flash,timer,actionscript,Flash,Timer,Actionscript,我正在为我的项目使用ActionScript2.0。我有一个计时器和一个沿x轴移动的电影剪辑。如果该电影剪辑到达给定的边界,它将消失并添加 定时器的速度。我的问题是我不能增加计时器的速度。以下是我的计时器的代码: stop(); var hour:Number = 0; var minute:Number = 0; var second:Number = 0; hours.text = "0" + hour; minutes.text = "0" + minute; seconds.text

我正在为我的项目使用ActionScript2.0。我有一个计时器和一个沿x轴移动的电影剪辑。如果该电影剪辑到达给定的边界,它将消失并添加 定时器的速度。我的问题是我不能增加计时器的速度。以下是我的计时器的代码:

stop();
var hour:Number = 0;
var minute:Number = 0;
var second:Number = 0;

hours.text = "0" + hour;
minutes.text = "0" + minute;
seconds.text = "0" + second;

timerClip.onEnterFrame = function(){
if(this._currentframe == 30){
second += 1;

if (second > 59){
    second = 0;
    seconds.text = "0" + second;
    minute += 1;
    minutes.text = "0" + minute;
} else {
    if (second >= 10) {
    seconds.text = second;
    } else {
        seconds.text = "0" + second;
    }

if (minute == 1){
    gotoandstop(2);
}
}
}
}
下面是我的电影剪辑代码:

onClipEvent (load) {
speed = 1;
boundary = 280; 

}

onClipEvent (enterFrame) {
if (this._x > boundary) {
    this._x -= speed;

} 
else {
    this._x = boundary;
    this._visible = false;

}
}

你应该这样做:

°创建一个函数startTimer,将OneInterFrame函数嵌套在其中,以便以后调用。
“为什么不把你的MovieClip代码写在时间线上,作为你的计时器的代码呢?” °当MovieClip的enterFrame不再有用时,您应该删除它。
°您现在可以通过调用函数startTimer启动计时器。


备注

你的计时器工作不正常。它会在每个enterFrame中添加一个伪秒,如果此enterFrame的帧速为24 fps,则它将计算24秒而不是1秒

function startTimer():Void {
    timerClip.onEnterFrame = function() {
        // Timer here...
    }
}

speed = 1;
boundary = 280;

clip.onEnterFrame = function():Void {
    if (this._x > boundary) {
        this._x -= speed;
    } else {
        this._x = boundary;
        this._visible = false;
        startTimer(); // start your Timer
        delete this.onEnterFrame; // delete your enterFrame
    }
}