1 Reply Latest reply on Dec 8, 2010 7:55 AM by iamcootis

    Problems with Timer, counts 60000 as one minute but need it to be 60

    djh88ukwb Level 1

      Hello All.

       

      I have an application that i have working although i need to change it slightly, the way that it uses a number to be exact,

       

      It includes a countdown HSlider and timer, and is used as an interview kinda thing.  so the user only gets a small period of pre determined time to make their answer.  It all works fine but i need to change one part of it.

       

      At the moment the timer works if i feed in the number 60000 as the maximum value,  this equals one minute, but i need to be able to enter 60 instead of 60000.  I need to use seconds rather than miliseconds.

       

      Here is my code.

       

                  protected function addtoArray():void {   
                      if(userArray.getItemAt(0).q1 != '') questionArray.addItem({question:userArray.getItemAt(0).q1, time:'60000', tt:'2'});
                      if(userArray.getItemAt(0).q2 != '') questionArray.addItem({question:userArray.getItemAt(0).q2, time:'60000', tt:'3'});
                      if(userArray.getItemAt(0).q3 != '') questionArray.addItem({question:userArray.getItemAt(0).q3, time:'30000', tt:'4'});
                      if(userArray.getItemAt(0).q4 != '') questionArray.addItem({question:userArray.getItemAt(0).q4, time:'60000', tt:'2'});
                  }

                  private function init():void {
                      t = new Timer(1000);
                      t.addEventListener(TimerEvent.TIMER, updateTimer);
                      startInterview();
                  }
                  private function updateTimer(evt:TimerEvent):void {
                      var d:Date = new Date(getTimer() - baseTimer);
                      counter.text = "Time Remaining - " + dateFormatter.format(d);
                      timerCount = getTimer() -baseTimer;
                      TimerSlider.value = timerCount;
                     
                      if (skip == true)
                      {
                          stopTimer();
                          startInterview();
                          skip = false;
                      }   
                      else if (timerCount >= totaltime)
                      {
                          stopTimer();
                          startInterview();
                      }
                  }

                  private function startInterview():void {
                      if(i==0)
                      {
                          questionArray.addItem({question:"End"});
                      }
                      timeLabel.text = questionArray.getItemAt(i).time;
                      totaltime = parseInt(timeLabel.text);
                      QuestionText.text = questionArray.getItemAt(i).question;
                      ThinkTime = questionArray.getItemAt(i).tt;
                     
                     
                      if (QuestionText.text=="End")
                      {
                          QuestionText.text = "Thanks, thats the end";
                      }
                      else
                      {
                          createComplete();
                          var QcountVar:int = questionArray.length -1;
                          var Qpos:int = i+1;
                          hp.status ="Question: " + Qpos.toString() + " / " + QcountVar.toString();
                          i = i + 1;
                      }
                  }

       

       

      The init function is called by a button click

       

      If anyone could help me change it so it runs in seconds rather than miliseconds that would be great !

       

      Thanks in advance