我有三个框架“800”,“450”和“635”
我更新了代码,它现在每1秒跳转到帧到帧。那不是我需要的。我需要计数器达到0并且它跳到一帧然后停在那里。多数民众赞成。
[更新2 ]见横幅 - http://magnixsolutions.com/clients/OT/9995MB-Scoreboard-April-160x600.swf
AS3 -
var fromFrame:int = 1;
var myTimer:Timer = new Timer(1000, nCount);
var frameNum:int = Math.ceil(Math.random() * mcYourScore.totalFrames)
timer_txt.text = nCount.toString();
myTimer.start();
myTimer.addEventListener(TimerEvent.TIMER, countdown);
function getRandomFromRange(minValue:Number, maxValue:Number):int {
return Math.round(minValue + Math.random() * (maxValue - minValue));
}
function countdown(e:TimerEvent):void {
//Display countdown
timer_txt.text = String(myTimer.repeatCount - myTimer.currentCount);
//if End of countdown, start from 2 frame
fromFrame = (myTimer.repeatCount == myTimer.currentCount) ? 2 : 1;
mcYourScore.gotoAndStop(getRandomFromRange(fromFrame, mcYourScore.totalFrames));
}
答案 0 :(得分:1)
Math.round(Math.random())没有任何意义,它只返回0或1个值。
var frameNum:int = Math.round(1 + Math.random() * (mcYourScore.totalFrames-1));
如果您想在每个刻度线上访问随机帧,这种结构应该可以帮助您:
var seconds:int;
function getRandomFromRange(minValue:Number, maxValue:Number):int {
return Math.round(minValue + Math.random() * (maxValue - minValue));
}
function countdown(e:TimerEvent):void {
//Display countdown
seconds = myTimer.repeatCount - myTimer.currentCount;
timer_txt.text = seconds.toString();
//if End of countdown, start from 2 frame
mcYourScore.gotoAndStop(getRandomFromRange(((seconds == 0) ? 2 : 1), mcYourScore.totalFrames));
}
如果您只想在倒计时结束时访问随机帧,可以使用TimerEvent.TIMER_COMPLETE
事件处理程序,或更改countdown
逻辑:
function countdown(e:TimerEvent):void {
//Display countdown
timer_txt.text = String(myTimer.repeatCount - myTimer.currentCount);
//if End of countdown, pick random frame, from 2 frame
if(myTimer.repeatCount == myTimer.currentCount){
mcYourScore.gotoAndStop(getRandomFromRange(2, mcYourScore.totalFrames));
}
}