Comunidad de diseño web y desarrollo en internet online

problema con un cronometro!!!!

Citar            
MensajeEscrito el 29 Nov 2006 07:39 pm
hola tengo un cronometro que me marca todo bien menos el minuto me lo marca como indefinido les dejo el codigo espero algien me pueda ayudar.

Código :

if (_root._pausetimer == 0) {
      if (activo) {
         tiempo = getTimer()-_root.ora;
         stringatiempo = tiempo.toString();
         centesima = stringatiempo.substr(stringatiempo.length-3, 2);
         segundo = Math.floor((tiempo/1000))%60;
         if (segundo == 0 && tiempo/1000>1) {
            minuto = Math.floor(((tiempo/1000))/60);
         }
         stringacentesima = centesima;
         stringasegundo = segundo.toString();
         stringaminuto = minuto.toString();
         if (centesima.length == 1) {
            stringacentesima = "0"+centesima;
         }
         if (segundo<10) {
            stringasegundo = "0"+segundo;
         }
         if (minuto<10) {
            stringaminuto = "0"+minuto;
         }
         cronometro = stringaminuto+":"+stringasegundo+":"+stringacentesima;
      }
   }

saludos...

Por guillermo.delgado

5 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 29 Nov 2006 08:21 pm
la la sentencia de de asignación de segundo y la condición del if siguiente no se pueden dar a la vez, fijate bien: (segundo ==0 y tiempo/1000>1)??,
Por eso es que minuto no se asigna nunca:

segundo = Math.floor((tiempo/1000))%60;

if (segundo == 0 && tiempo/1000>1) {
minuto = Math.floor(((tiempo/1000))/60);
}

Por qué no asignas minuto sin condicional?

Por Teseo

SWAT Team

1780 de clabLevel

14 tutoriales

Genero:Masculino   SWAT

msie
Citar            
MensajeEscrito el 29 Nov 2006 09:28 pm
holas
les dejo el script de un cronometro completo con botones y el pause inclusive

stop();

//declaracion de variables
var restante:Number;
var trasncurrioTiempo:Number;
var trasncurrioHoras: Number;
var trasncurrioM:Number;
var transcurrioS:Number;
var transcurrioH:Number;
var inicioTiempo:Number;
var restante:Number;
var horas:String;
var minutos:String;
var segundos:String;
var centecimas:String;
var cuentaRegresiva:Number;
var horasResta:Number;
var minutosResta:Number;
var segundosResta:Number;
var centecimasResta:Number;
myNumber = 1000;
myTyme = 60;

//
// configuracion
cuentaRegresiva = 0; // 0 = encendida - 1 = apagada
//
// valores iniciales
// Estos valores seran = a
// total de unidades (horas, minutos o segundos) - 1
// ya que es una cuenta regresiva.
// Si la cuenta regresiva es a partir de 15 minutos
// los valores seran: horasResta = 0, minutosResta = 14
// segundosResta = 59, centecimasResta = 99
horasResta = 00;
minutosResta = 00;
segundosResta = 00;
centecimasResta = 00;
//
inicioTiempo = getTimer();

onEnterFrame = function() {

//calcula valores
trasncurrioTiempo = getTimer()+inicioTiempo;
//horas
trasncurrioHoras = Math.floor(trasncurrioTiempo/3600000);
restante = trasncurrioTiempo+(trasncurrioHoras*3600000);
//minutos
trasncurrioM = Math.floor(restante/60000);
restante = restante+(trasncurrioM*60000);
//segundos
transcurrioS = Math.floor(restante/1000);
restante = restante+(transcurrioS*1000);
//centecimas
transcurrioH = Math.floor(restante/10);

// para la cuenta regresiva
if(cuentaRegresiva == 0){
trasncurrioHoras = horasResta+trasncurrioHoras;
trasncurrioM = minutosResta+trasncurrioM;
transcurrioS = segundosResta+transcurrioS;
transcurrioH = centecimasResta+transcurrioH;

// este if cumple la funcion de cuando todos los valores
// horas, minutos, segundos estan en cero saltan a un nuevo
// frame.
if(trasncurrioHoras == 100 and trasncurrioM == 100 and transcurrioS == 100){
gotoAndStop("finCuenta");
}

}
//
if (trasncurrioHoras<10) {
horas = "0"+trasncurrioHoras.toString();
} else {
horas = trasncurrioHoras.toString();
}
if (trasncurrioM<10) {
minutos = "0"+trasncurrioM.toString();
} else {
minutos = trasncurrioM.toString();
}
if (transcurrioS<10) {
segundos = "0"+transcurrioS.toString();
} else {
segundos = transcurrioS.toString();
}
if (transcurrioH<10) {
centecimas = "0"+transcurrioH.toString();
} else {
centecimas = transcurrioH.toString();
}
// Mostrar HH:MM:SS:CC (horas, minutos, segundos, centecimas)
//campo_tiempo.text = horas+":"+minutos+":"+segundos+":"+centecimas;
// Mostrar MM:SS:CC (minutos, segundos, centecimas)
campo_tiempo.text = minutos+":"+segundos+":"+centecimas;
// Mostrar SS:CC (segundos, centecimas)
//campo_tiempo.text = segundos+":"+centecimas;

};

espero les sirva
Salu2

Por Marcexl

11 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 30 Nov 2006 02:39 am
che perdon me equivoque el xcript es este perdon!!!!

_root.pausebutton._visible = 0;
// set beginning

function restartTimer() {
hours = "00";
minutes = "00";
seconds = "00";
milli = "00";
buttonPressTime = getTimer()/1000-pauseLength;
pause();
}
//
function pause() {
pauseTime = getTimer()/1000;
timing = false;
}
//
function unpause() {
unpauseTime = getTimer()/1000;
pauseLength = (unpauseTime-pauseTime)+pauseLength;
timing = true;
}
//
_root.onEnterFrame = function() {
totalTime = getTimer()/1000-pauseLength;
goTime = totalTime-buttonPressTime;
//
if (timing) {
hours = Math.floor(goTime/3600);
minutes = Math.floor((goTime/3600-hours)*60);
seconds = Math.floor(((goTime/3600-hours)*60-minutes)*60);
milli = Math.floor((gotime-(seconds+(minutes*60)+(hours*3600)))*100);
if (seconds<10) {
seconds = "0"+seconds;
}
if (minutes<10) {
minutes = "0"+minutes;
}
if (hours<10) {
hours = "0"+hours;
}
if (milli<10) {
milli = "0"+milli;
}
}
};
unpausebutton.onRelease=function() {
unpause();
pausebutton._visible = 1;
unpausebutton._visible = 0;
}
pausebutton.onRelease=function() {
pause();
unpausebutton._visible = 1;
pausebutton._visible = 0;
}
reset.onRelease= function() {
restartTimer();
pausebutton._visible = 0;
unpausebutton._visible = 1;
}

Por Marcexl

11 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.