2015-01-05 50 views
0

我爲我的項目使用了ActionScript 2.0。我有一個定時器和一個沿x軸移動的影片剪輯。如果該影片剪輯到達給定邊界,它將消失並添加定時器的速度。我的問題是我無法添加計時器的速度。這裏是我的計時器代碼:Actionscript 2.0計時器

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; 

} 
} 

回答

0

你應該做這樣的:

°創建一個函數startTimer所窩了onEnterFrame函數,稍後調用它。
°爲什麼不把你的MovieClip的代碼作爲你的定時器的代碼寫在TimeLine上?
°你應該刪除你的MovieClip的enterFrame,當它沒有用了。
°你現在可以通過調用你的函數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 
    } 
} 

備註

你的計時器無法正常工作。它在每個enterFrame中添加一個僞秒,如果enterFrame的幀數爲24 fps,則它將計數24秒而不是一個。