Try to use this code. i used that to create a cutdown timer for flash cs3 ,
so will give you an idea on how to do that.
this.onEnterFrame = function() {
var hoje:Date = new Date();
var anoAtual:Number = hoje.getFullYear();
var horaAtual:Number = hoje.getTime();
var dataEvento:Date = new Date(anoAtual, 9, 2);
var tempoAlvo:Number = dataEvento.getTime();
var tempoRestante:Number = tempoAlvo-horaAtual;
var segundos = Math.floor(tempoRestante/1000);
var minutos = Math.floor(segundos/60);
var horas = Math.floor(minutos/60);
var dias = Math.floor(horas/24);
// iniciando o contagem regressiva
segundos = String(segundos%60);
if (segundos.length<2) {
segundos = "0" + segundos;
}
minutos = String(minutos%60);
if (minutos.length<2) {
minutos = "0"+ minutos;
}
horas = String(horas%24);
if (horas.length<2) {
horas = "0"+horas;
}
dias = String(dias);
var contador:String = dias+":"+horas+":"+minutos+":"+segundos;
// tempo_txt
tempo_txt.text = contador;
// Finalizando
};
regards
igor Costa
www.igorcosta.org
www.igorcosta.com
On Dec 10, 2007 7:25 PM, markcavins <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I have a very functional timer here that I am using but I would like
> to get some advice on how to make it better.
>
> Code:
>
> private function getDaysUntil():void {
> // creates a new five-minute Timer
> var minuteTimer:Timer = new Timer(1000, 300);
>
> // designates listeners for the interval and completion events
> minuteTimer.addEventListener(TimerEvent.TIMER, onTick);
> minuteTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
>
> // starts the timer ticking
>
> minuteTimer.start();
> }
>
> public function onTick(evt:TimerEvent):void {
> var minuteTimer:Timer = evt.target as Timer;
> lblTimeUntil.text = minuteTimer.currentCount.toString();
> }
>
> public function onTimerComplete(evt:TimerEvent):void
> {
> var minuteTimer:Timer = evt.target as Timer;
> minuteTimer.reset();
>
> minuteTimer.start();
> }
>
> I would like to be able to split the time into minutes and seconds.
>
> Also I would like to get it to count down instead of up.
>
>
>
--
----------------------------
Igor Costa
www.igorcosta.com
www.igorcosta.org