2015-01-05 47 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秒而不是一个。