0
votes

I am using an ActionScript 2.0 for my project. I have a timer and a movie clip that is moving along the x-axis. If that movie clip reaches the given boundary, it will disappear and add the speed of the timer. My problem is i can't add the speed of the timer. Here is the code for my timer :

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);
}
}
}
}

and here is my code for my movie clip:

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

}

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

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

}
}
1

1 Answers

0
votes

You should do like that:

° Create a function startTimer to nest the onEnterFrame function within it, to call it later.
° Why not writing your MovieClip's code on the TimeLine as your timer's one?
° You should delete your MovieClip's enterFrame when it isn't useful any more.
° You can now start your timer by calling your function startTimer.


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
    }
}

Remark

Your Timer doesn't work correctly. It adds a pseudo-second every enterFrame, and if this enterFrame is of 24 fps, it will count 24 seconds instead of one.