简体   繁体   English

倒计时“ gotoAndPlay” AS3

[英]Countdown “gotoAndPlay” AS3

My timer counts down from 60 to zero . 我的计时器从60倒数到零 I want my movie to go to the next frame at zero count . 我希望我的电影以零计数转到下一帧。 How would I make a condition to go from frame 1-2 ? 我要如何设定从第1-2帧开始的条件? I need to find the right operator and values, but I get lost in the strings. 我需要找到正确的运算符和值,但是我迷失在字符串中。

WHAT I'M TRYING 我正在尝试
If (something is <> == true false); 如果(某事是<> == true false);
gotoAndPlay(2); gotoAndPlay(2);

stop();
//
var timer:Timer = new Timer(100, 300);
timer.addEventListener(TimerEvent.TIMER, countdown);
timer.start();
function countdown(event:TimerEvent) {
    var totalSecondsLeft:Number = 60 - timer.currentCount;
    myText.text = timeFormat(totalSecondsLeft);
}

function timeFormat(seconds:int):String {
  //  var minutes:int;
   // var sMinutes:String;
    var sSeconds:String;
    if(seconds > 59) {
    //    minutes = Math.floor(seconds / 60);
    //    sMinutes = String(minutes);
        sSeconds = String(seconds % 60);
    } else {
   //     sMinutes = "";
        sSeconds = String(seconds);
    }
    if(sSeconds.length == 1) {
        sSeconds = "0" + sSeconds;

            //###################################
            //}
            //if(bla bla bla?) {
            //gotoAndPlay(2);
            //###################################
    }
    return sSeconds;//return sMinutes + ":" + sSeconds;
}

I Tried This "Nothing" 我试过这个 “没事”

stop();
var timer:Timer = new Timer(1000); // delay = time between ticks in milliseconds
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();

function onTimer($evt:TimerEvent):void { 
    watch.hand.rotation = 30 + timer.currentCount;//tick 5 
} 

//function startAgain($evt:TimerEvent):void { 
//timer.reset(); 
//timer.start(); 
//} 

function onTimerComplete(e:TimerEvent):void
{

    // remove listener
    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
    // advance playhead to frame 2
    gotoAndPlay(2);
}

I'm making several experiments like this to understand conditionals. 我正在做这样的几个实验以了解条件。 I need to build objects that function similar to preloaders. 我需要构建功能类似于预加载器的对象。

alt text http://www.ashcraftband.com/myspace/videodnd/board1.jpg 替代文字http://www.ashcraftband.com/myspace/videodnd/board1.jpg

If your question is about advancing the playhead from frame 1 to frame 2 after 60 ticks then I would suggest you listen for a TimerEvent.TIMER_COMPLETE event. 如果您的问题是在60个滴答声之后将播放头从第1帧前进到第2帧,那么我建议您监听TimerEvent.TIMER_COMPLETE事件。 For example, 例如,

var timer:Timer = new Timer(delay, 60); // delay = time between ticks in milliseconds
timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
timer.start();

function onTimerComplete(e:TimerEvent):void
{
    // remove listener
    timer.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);

    // advance playhead to frame 2
    gotoAndPlay(2);
}

As for your question about conditionals... you ask, "How would I make a condition to go from frame 1-2?" 至于关于条件句的问题……您会问:“我将如何制定从第1-2帧开始的条件?” Well, what does the condition require in order to advance a frame? 那么,条件要求什么才能前进一帧?

Please try to ask clear and concise questions. 请尝试提出清晰简洁的问题。 If you are just trying to wrap your head around conditionals then I suggest you search google and this site as there is a ton of good information out there. 如果您只是想把条件放在头上,那么我建议您搜索google和这个网站,因为那里有很多很好的信息。 Good luck! 祝好运!

==== Edit ==== ====编辑====

The code you added 2 days ago (ie I Tried This "Nothing"...) shouldn't do anything :) 您两天前添加的代码(即,我尝试了此“无” ...)不应执行任何操作:)

The following line of code instantiates a Timer object that will tick every 1000 milliseconds forever : 以下代码行实例化了一个Timer对象,该对象将每1000毫秒永远计时一次:

var timer:Timer = new Timer(1000);

This is why your onTimerComplete(e:TimerEvent) handler never gets called. 这就是为什么永远不会调用onTimerComplete(e:TimerEvent)处理程序的原因。 If you want it to eventually stop ticking, say after 5 seconds, you would want to use the following snippet in place of yours: 如果您希望它最终停止计时,例如5秒钟后,您可以使用以下代码段代替您的代码段:

var timer:Timer = new Timer(1000, 5); // timer will tick every second (1000 milliseconds) for 5 seconds

You also never register a TimerEvent.TIMER event handler. 您也永远不会注册TimerEvent.TIMER事件处理程序。 This is why your onTimer($evt:TimerEvent) handler never gets called. 这就是为什么永远不会调用onTimer($evt:TimerEvent)处理程序的原因。 If you want to capture that event you will need to register the handler like so: 如果要捕获该事件,则需要像下面这样注册处理程序:

timer.addEventListener(TimerEvent.TIMER, onTimer);

If you add that listener be sure to remove it in the onTimerComplete(e:TimerEvent) handler in the same manner the TimerEvent.TIMER_COMPLETE handler is removed. 如果您添加监听器一定要在删除它onTimerComplete(e:TimerEvent)处理程序中相同的方式TimerEvent.TIMER_COMPLETE处理器也会被删除。

Hope this helps. 希望这可以帮助。 Good luck! 祝好运!

Alternatively, you could use the setTimeout function: 另外,您可以使用setTimeout函数:

function goToTwo(e) {
   gotoAndPlay(2);
}

setTimeout(goToTwo, 60*1000);

You say you want to go to the next frame . 您说要转到下一帧 I'm not exactly sure what you're looking for, but is it the nextFrame() function? 我不确定您要寻找什么,但这是nextFrame()函数吗? or gotoAndStop()? 或gotoAndStop()?

Can you try to re-explain what you're looking to have happen here? 您可以尝试重新解释您在这里发生的事情吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM