1 Reply Latest reply on Jan 23, 2008 6:21 PM by

    killing the clock

    Tigomark
      Hello,

      I have this clock that runs as a countdown timer once a user logs into
      the site. It works great until the user logs out. When they log back
      in the counter no longer counts correctly. It is like there are 2
      intstances of the clock running at the same time but I'm not sure how
      to kill the first instance.

      Clock code
      Code:

      private function getDaysUntil():void {
      //setting the timer
      var minuteTimer:Timer = new Timer(1000, 300);
      minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
      minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE,
      onTimerComplete);

      minuteTimer.start();
      }

      public function onTick(evt:TimerEvent):void {
      var minuteTimer:Timer = evt.target as Timer;
      var lvSecondsRemaining:int = minuteTimer.repeatCount -
      minuteTimer.currentCount;
      var lvMinutes:int = lvSecondsRemaining / 60;
      var lvSeconds:int = lvSecondsRemaining - ( lvMinutes * 60 );
      var lvSecondsText:String = lvSeconds.toString();
      if( lvSeconds < 10 ) lvSecondsText = "0" + lvSecondsText;

      lblTimeUntil.text = lvMinutes.toString() + ":" + lvSecondsText;

      }

      public function onTimerComplete(evt:TimerEvent):void{
      var minuteTimer:Timer = evt.target as Timer;
      minuteTimer.reset();
      minuteTimer.start();
      tempXML.send();

      }


      private function stopTimer():void{
      var minuteTimer:Timer = new Timer(1000, 300);
      minuteTimer.reset();
      minuteTimer.stop();
      clearFormHandler();

      }

      Here is the logout button and the login button
      Code:

      <mx:Button label="Log Out" height="27" fillAlphas="[1.0, 1.0]"
      fillColors="[#030000, #030000, #474545, #474545]"
      borderColor="#DCDEDF" click="currentState=''; stopTimer();"/>


      <mx:Button x="10" y="282" label="Login" id="Submit"
      click="login_user.send();"
      fontSize="14" themeColor="#FFA800" borderColor="#FA0202"
      enabled="{formIsValid}" />

      If the user is able to login
      Code:

      currentState = "Logged In";

      tempXML.send();
      getDaysUntil();

      Any ideas how to get this to display right
        • 1. Re: killing the clock
          Hi, I can se that you create 2 Timer instances on local variables (inside functions) wich you use to start and stop timer with. Each object run independent from each other, Lookup object oriented programming objects and Classes.

          What you have to do is to declare a local timer object in top of .mxml mx:script block "private var myTimer:Timer();"

          Then in creationComplete event create ONE timer object "myTimer = new Timer();"

          Then you call myTimer.Stop(); or myTimer.Start();