Skip navigation
Currently Being Moderated

Go to Scene after Countdown

Jun 11, 2012 5:41 AM

I have a simple countdown timer, after which I would like to automatically go to a specific scene after the timer times out.

I am pretty new to AS3.

I have tried the gotoANDPlay ("Scene 1", 1); after the code, but it doesn't seem to work.

Any suggestions would be appreciated.

Here is my timer code:

 

var timer:Timer = new Timer(1000, 21);

timer.addEventListener(TimerEvent.TIMER, countdown);

timer.start();

function countdown(event:TimerEvent) {

cooling1.text = String(21 - timer.currentCount);

cooling2.text = String(21 - timer.currentCount);

cooling3.text = String(21 - timer.currentCount);

}

 

What do I put here to automatically send me another scene?

 

Thanks,

Bob

 
Replies
  • Currently Being Moderated
    Jun 11, 2012 5:44 AM   in reply to Bobgraphics101

    Case matters and the order of the arguments as well.  The order you show would work for AS2, but not AS3.  The correct command would be...

     

        gotoAndPlay(1, "Scene 1");

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 9:11 AM   in reply to Bobgraphics101

    That gotoAndPlay command will execute almost immediately, having no relationship to the countdown.  So if that line is in frame 1 of the main timeline, it executes immediately when you start running the file and simply puts you where you already are.  It needs to be conained within some function in order to have it happen at some later point in time when the function is called.

     

    If you want that code to execute after the timer has timed out its 21 counts, then you will need to have an event listener for the TIMER_COMPLETE event, and inside that listeners event handler function is where you want to put that gotoAndPlay command.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 12:57 PM   in reply to Bobgraphics101

    Short of writing it out for you, I explained what code you need.  What part of it are you not able to write?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 2:19 PM   in reply to Bobgraphics101

    But the function only needs to contain the one line: gotoAndPlay(1, "Scene 1"); 

     

    I think you need to learn something more basic than something specific to Timer events.  There are event listeners and event handler functions for those listeners.  You have already used one set of them in the code you showed...

     

    // this is the listener

    timer.addEventListener(TimerEvent.TIMER, countdown);  

     

    // this is the event handler function for that listener

    function countdown(event:TimerEvent):void {    

          // actions to take when event occurs

    }

     

    You should be able to use the above as the basis for creating another listener/handler set.  What will the TIMER_COMPLETE listener look like?  What will the handler function look like for the gotoAndPlay command that you need to trigger when the TIMER_COMPLETE event occurs?

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 4:42 PM   in reply to Bobgraphics101

    You aren't putting me out.  Moreso I am putting you out.  Others that help around here would have handed you the code a few postings back, but I prefer to try to help people solve things rather than hand them solutions.  I wouldn't be surprised if one of them jumpps in

     

    If you can gain the simple concept of an event listener and its handler, you will have gained something that applies throughtout Actionscript and is used everywhere.  The way they are implemented is the same across the board.  You create a listener and you create its handler function... the event when it occurs causes the handler function to execute whatever code it contains.

     

    In the code you showed, a handler function was created named countdown.  THe event listener for it is listeneing for a TIMER event.   The function could  have been named anything you like.  The name of the function has to be unique though, so any new one you create for another purpose needs a different name.

     

    Now you need to create another listener for the TIMER_COMPLETE event for that Timer object that you have.  So create the new event listener by modeling it after the one you have, just specify the new event type and a new function for it to call... then create the new event handler function for it too, again modeling it after the one you have already, but put the new code inside it that you want it to execute. 

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 11, 2012 5:21 PM   in reply to Ned Murphy

    i wanna jump in

     

    but the answer is already there, 3 posts up...

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 12, 2012 4:21 AM   in reply to Bobgraphics101

    You're welcome

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points