Skip to main content
Inspiring
April 23, 2015
Question

Simple Countdown Script behaving strange on iOS [HELP]

  • April 23, 2015
  • 0 replies
  • 185 views

I have a basic countdown script that I've used in the past in old Flash project. For some reason when I run it in an iOS app it behaves strange. I am also looking at the best approach to modify so I can set my countdown variable to accept a value such as  2:15  ( Two minutes & 15 seconds ) rather than just whole numbers.

The weirdness is that if I set it to countdown 2 minutes...  I can see the timer start at 2:00   .. but then it jumps to 1:57 and never shows  1:59  1:58

Here is my script... is there a better way to do this ?

As always .. any help is appreciated.

// I would like to be able to use values such as  2:15

var theTime:int = 2;

var endTime:Number = getTimer();

var countdownTimer:Timer = new Timer(1000);

countdownTimer.addEventListener(TimerEvent.TIMER, updateTime);

function updateTime(e:TimerEvent):void

{

  var timeLeft:Number = endTime - getTimer();

  var seconds:Number = Math.floor(timeLeft / 1000);

  var minutes:Number = Math.floor(seconds / 60);

  seconds %= 60;

  minutes %= 60;

  var sec:String = seconds.toString();

  var min:String = minutes.toString();

 

if (sec.length < 2) {

    sec = "0" + sec;

  }

  var time:String = min + ":" + sec;

  time_txt.text = time;

 

  if(minutes == 0 && seconds == 0){

  

   trace("TIME ENDED");

  

  countdownTimer.stop();

  

   }

}

function resetTimer():void{

  endTime = getTimer();

  countdownTimer.reset();

}

function startTimer():void{

  endTime += theTime*60*1000;  //adjust endTime to 15 minutes in the future.

countdownTimer.start();

}

This topic has been closed for replies.