views:

319

answers:

3

My timer counts down from 60 to zero. 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? 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);
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

+1  A: 

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. 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?" 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. Good luck!

==== Edit ====

The code you added 2 days ago (i.e. I Tried This "Nothing"...) shouldn't do anything :)

The following line of code instantiates a Timer object that will tick every 1000 milliseconds forever:

var timer:Timer = new Timer(1000);

This is why your onTimerComplete(e:TimerEvent) handler never gets called. If you want it to eventually stop ticking, say after 5 seconds, you would want to use the following snippet in place of yours:

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. This is why your onTimer($evt:TimerEvent) handler never gets called. 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.

Hope this helps. Good luck!

heavilyinvolved
Thanks man. Good explanation of Event handling. Answer to my problems!
VideoDnd
A: 

Alternatively, you could use the setTimeout function:

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

setTimeout(goToTwo, 60*1000);
Şafak Gezer
A: 

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? or gotoAndStop()?

Can you try to re-explain what you're looking to have happen here?

Cam
gotoAndStop. I'm adding stop(); to frame1 and frame2
VideoDnd