Alguien tiene un ejemplo de como hacer un reloj countdown....
quiero ingresar una fecha y me ponga un reloj contando lo que falta hasta la fecha ingresada.
 
gracias y saludos 
  | 
 | ||||
|  Re: Reloj contador....   Algo asi?, esto solo funciona con un tiempo menor a 1 dia, obviamente se puede hacer mas complicado 
Código:
 var now:Date = new Date();
var stopDate:Date = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes()+5);
var interval:Number = setInterval(calculateTime, 1000);
function calculateTime()
{
	now = new Date();
	var rest:Date = new Date(stopDate.getTime() - now.getTime());
	trace(rest.getHours() + ":" + rest.getMinutes() + ":" + rest.getSeconds());
	if(now.getTime() >= stopDate.getTime()) clearInterval(interval);
}
 | 
| 
 | ||||
|  Re: Reloj contador....   Les muestro lo que tengo y el problema esta que las horas me da papa fritas jejeje F_final = new Date(); F_final.setYear(2007); F_final.setDate(8); F_final.setMonth(9); F_final.setHours(15); F_final.setMinutes(0); F_final.setSeconds(0); F_final.setMilliseconds(0); objeto_fecha = new Date(); horas = ""; horas = objeto_fecha.getHours(); horas = horas + 2; if (horas < 10) { horas = "0" + horas; } // end if minutos = objeto_fecha.getMinutes(); minutos_digito = ""; if (minutos < 10) { minutos_digito = "0"; } // end if minutos_digito = minutos_digito + objeto_fecha.getMinutes(); segundos = objeto_fecha.getSeconds(); segundos_digito = ""; if (segundos < 10) { segundos_digito = "0"; } // end if segundos_digito = segundos_digito + objeto_fecha.getSeconds(); Fecha = new Date(); F_actual = Fecha.getTime(); F_final = Math.floor(F_final / 86400000); F_actual = Math.floor(F_actual / 86400000); D_faltan = F_final - F_actual; objetivo_segundos = 60 - segundos_digito; if (objetivo_segundos < 10) { objetivo_segundos = "0" + objetivo_segundos; } // end if if (objetivo_segundos == "60") { objetivo_segundos = "00"; --minutos_digito; } // end if objetivo_minutos = 59 - minutos_digito; if (objetivo_minutos < 10) { objetivo_minutos = "0" + objetivo_minutos; } // end if if (objetivo_minutos > 59) { objetivo_minutos = "00"; --horas; } // end if objetivo_horas = 23 - horas; if (objetivo_horas < 10) { objetivo_horas = "0" + objetivo_horas; } // end if if (objetivo_horas == "0-1") { objetivo_horas = "23"; --D_faltan; } // end if if (objetivo_horas == "0-2") { objetivo_horas = "22"; --D_faltan; } // end if if (D_faltan < 10) { D_faltan2 = "00" add D_faltan; } else if (D_faltan < 100) { D_faltan2 = "0" add D_faltan; } else { D_faltan2 = String(D_faltan); } // end else if if (mbsubstring(D_faltan, 1, 2) == "0-") { contador.text = "El día ha llegado"; segundos_.text = ""; minutos_.text = ""; horas_.text = ""; dias_.text = ""; } else { contador.text = "FALTAN DIAS HORAS MINUTOS SEGUNDOS"; segundos_.text = objetivo_segundos; minutos_.text = objetivo_minutos; horas_.text = objetivo_horas; dias_.text = D_faltan; trace(horas_.text); } // end else if | 
| 
 | ||||
|  Re: Reloj contador....   mmm....ese codigo esta muy "sucio" y es un ejemplo viejisimo, todavia dice "add" que no se usa mas desde la version AS1, hay como 70 lineas que las puedes resolver en una funcion. Apenas llego a casa te mando como hacerlo. Ciao!.  | 
| 
 | ||||
|  Re: Reloj contador....   Como prometido...me ha costado pero aca esta. (se hace un poco largo por los comentarios) =) 
Código:
 //Creo un textField para mostrar lo que falta hasta "el dia del juicio"...
this.createTextField("tf", 0, 100, 100, 400, 100);
var tf:TextField = this["tf"];
//Para que sea mas comprensible.
//Creo un objeto con los datos, año, mes, dia.
var elDiaFinal:Object = new Object();
elDiaFinal["anio"] = 2008;
elDiaFinal["mes"] = 7; //ActionScript empieza a contar los meses en este modo Enero = 0, Febrero = 1....
elDiaFinal["dia"] = 14;
elDiaFinal["hora"] = 18;
elDiaFinal["minutos"] = 22;
elDiaFinal["segundos"] = 34;
//¿Qué fecha es hoy?
var now:Date = new Date();
//¿Cuando es el dia final?
var stopDate:Date = new Date(elDiaFinal["anio"], elDiaFinal["mes"], elDiaFinal["dia"], elDiaFinal["hora"], elDiaFinal["minutos"], elDiaFinal["segundos"]);
//Cada 1 segundo actualizo los datos llamando la funcion "calculateTime"
var interval:Number = setInterval(calculateTime, 1000);
function calculateTime()
{
	//Cada vez que calculo el tiempo creo un nueva fecha, o sea actualizada
	//para poder ir haciendo el calculo "ahora" - "lo que falta"
	now = new Date();
	var rest:Date = new Date(stopDate.getTime() - now.getTime()); //Creo una nueva fecha con "el resto del tiempo"
	
	//Le resto siempre un dia porque para AS 1 dia quiere decir = el mismo dia...o sea 0
	var dias:Number = (rest.getDate() > 0) ? (rest.getDate()-1) : 0;
	var anios:Number = stopDate.getFullYear() - now.getFullYear(); 	//Calculo la cantidad de años que faltan
	
	//Creo una String con el texto a visualizar, haciendo algunas comprobaciones...
	//Si es plural agrego una "N" o una "S" segun el caso.
	//Si el numero tiene solo un digito lo convierto en 2, por ej. "2" en "02"
	var strFalta:String = "FALTA";
	strFalta += (anios != 1 ? "N " : " ") + anios + " AÑO" + isPlural(anios);
	strFalta += dias + " DIA" + (dias != 1 ? "S " : " ");
	strFalta += convertirDosDigitos(rest.getHours()) + " HORA" + isPlural(rest.getHours());
	strFalta += convertirDosDigitos(rest.getMinutes()) + " MINUTO" + isPlural(rest.getMinutes());
	strFalta += " Y " + convertirDosDigitos(rest.getSeconds()) + " SEGUNDO" + isPlural(rest.getSeconds());
	
	//Visualizo el texto
	tf.text = strFalta;
	
	//Si la fecha "ahora" es igual al "dia final" elimino el contador
	if(now.getTime() >= stopDate.getTime()) clearInterval(interval);
}
function convertirDosDigitos(num:Number):String
{
	//Compruebo si el numero tiene uno o dos digitos
	//Si tiene uno le agrego un "0"
	if(String(num).length == 1)
		return ("0" + String(num));
	return String(num);
}
function isPlural(num:Number):String
{
	//Si el numero pasado es mayor a uno quiere decir
	//que el adjetivo sera pural, por lo tanto le agrego una "S"
	if(num > 1) return "S ";
	return " ";
}
 |