2 Replies Latest reply on Dec 31, 2009 6:43 AM by pauland

    Timer doubles duration at end of the loop

    pir897

      I have a timer that automatically advances to the next state after 10 seconds.  When it gets to the last state it waits 20 seconds before transitioning to the first state.  How do I keep it from doubling the duration on the last state?

       

                  // timer
                  private var timer:Timer;
                 
                  private function init():void
                  {
                      timer = new Timer(10000);
                      timer.addEventListener(TimerEvent.TIMER, onTimer);
                      timer.start();           
                  }
                 
                  public var counter:int = 0;
                  public var myStates:Array;
                  
                  private function onTimer(evt:TimerEvent):void
                  {
                      if(myStates == null)myStates = this.states;
                      
                      if(counter!=states.length)
                      {
                          counter++;
                      }
                          
                      else
                      {
                          counter = 0;
                      }
                      
                      this.currentState = states[counter].name;                
                  }
                 
                  // start timer
                  private function startTimer():void
                  {
                      if (!timer.running) {
                          timer.start();
                      }
                  }
                 
                  // stop timer
                  private function stopTimer():void
                  {
                      if (!timer.running) {
                          timer.stop();
                      }
                  }