Skip to main content
Known Participant
October 6, 2013
Answered

Timer Issue

  • October 6, 2013
  • 1 reply
  • 915 views

I need a timer to wait 5 seconds after a button is clicked before displaying something else.  I am having trouble with this and I am sure its something I am doing wrong.  It seems to work but doesnt stop. 

Here is what I have so far any help would be appreciated.

function tortTimer()

          {

                    trace("Tort Timer");

                    var tortInterval:Timer = new Timer(750);

                    tortInterval.addEventListener(TimerEvent.TIMER, tortProcessing);

                    tortInterval.start();

          }

function tortProcessing (e:TimerEvent):void {

          if (rotationsPM < 20)

                    {

                              trace("Not long enough");

                              feeback_MC.visible = true;

                              tort_wrong.visible = true;

                              next_btn.visible = true;

                    } else if ( rotationsPM > 25) {

                              trace("Its overcooked");

                              feeback_MC.visible = true;

                              tort_wrong.visible = true;

                              next_btn.visible = true;

                    } else if (rotationsPM >=20 || rotationsPM <= 25) {

                              trace("Just Right");

                              feeback_MC.visible = true;

                              tort_right.visible = true;

                              next_btn.visible = true;

                              tortInterval.removeEventListener(TimerEvent.TIMER, tortProcessing);

                    }

}

This topic has been closed for replies.
Correct answer Ned Murphy

If you want the Timer to stop after a certain number of timeouts, even just 1, you need to specify that as its second argument.

If you want the second function to be able to target the Timer instance to remove its listener you need to declare the Timer outside of the first function so that it is available to other functions.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
October 6, 2013

If you want the Timer to stop after a certain number of timeouts, even just 1, you need to specify that as its second argument.

If you want the second function to be able to target the Timer instance to remove its listener you need to declare the Timer outside of the first function so that it is available to other functions.

Known Participant
October 6, 2013

Thanks. I knew it was something simple.

Ned Murphy
Legend
October 6, 2013

You're welcome