Comunidad de diseño web y desarrollo en internet online

Cuenta regresiva: Tomar al fecha desde un .txt externo

Citar            
MensajeEscrito el 15 Ago 2009 01:24 am
Buenas a todos.

Tengo un clic de pelicula que es una cuenta regresiva que la uso en una pagina web (Codigo tomado de un ej encontrado por la Web). Obviamente que para ser una cuenta regresiva tiene una fecha de referencia a la cual debe llegar.

El "problema" es justamente que me es un poco molesto tener que volver a configurar esa fecha cada vez que llega a 0: Entrar al .fla, modificarlo, resubirlo a la pagina, limpiar el cache para que no me tome el .swf viejo y demas...

Entonces me preguntaba: ¿Es muy dificil modificar el siguiente codigo para en vez de entrar a configurar todo esto que mensiono tome los datos directamente desde un .txt externo? (Como se hace, por ej, con los campos de texto). Yo lo he intentado pero no se me ha ocurrido la forma correcta para que me funcione.

Desde ya agradezco el tiempo y su ayuda.

Saludos!.

Código ActionScript :

onClipEvent (load) {
   countdown = "yes";
   // Target Time Information
   tyear = 2009;
   tmonth = 12;
   tday = 31;
   thours = 18;
   tminutes = 00;
   tseconds = 00;
   //
}
onClipEvent (enterFrame) {
   if (countdown == "yes") {
      mon = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
      daysinmonth = ["31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"];
      now = new Date();
      nyear = now.getFullYear();
      nmonth = mon[now.getMonth()];
      ndays = daysinmonth[now.getMonth()];
      nday = now.getDate();
      nhours = now.getHours();
      nminutes = now.getMinutes();
      nseconds = now.getSeconds();
      // Year Code
      ryear = tyear-nyear;
      //Month Code
      if (tmonth>=nmonth) {
         rmonth = tmonth-nmonth;
      } else {
         rmonth = (12-nmonth)+tmonth;
         ryear = ryear-1;
      }
      // Day Code
      if (tday>=nday) {
         rday = tday-nday;
      } else {
         rday = (ndays-nday)+tday;
         rmonth = rmonth-1;
         if (rmonth<0) {
            ryear = ryear-1;
            rmonth = 12+rmonth;
         }
      }
      // Hour Code
      if (thours>=nhours) {
         rhours = thours-nhours;
      } else {
         rhours = (24-nhours)+thours;
         rday = rday-1;
         if (rday<0) {
            rmonth = rmonth-1;
            rday = Number(ndays)+Number(rday);
            if (rmonth<0) {
               ryear = ryear-1;
               rmonth = 12+rmonth;
            }
         }
      }
      // Minute Code
      if (tminutes>=nminutes) {
         rminutes = tminutes-nminutes;
      } else {
         rminutes = (60-nminutes)+tminutes;
         rhours = rhours-1;
         if (rhours<0) {
            rday = rday-1;
            rhours = 24+rhours;
            if (rday<0) {
               rmonth = rmonth-1;
               rday = Number(ndays)+Number(rday);
               if (rmonth<0) {
                  ryear = ryear-1;
                  rmonth = 12+rmonth;
               }
            }
         }
      }
      // Seconds Code
      if (tseconds>=nseconds) {
         rseconds = tseconds-nseconds;
      } else {
         rseconds = (60-nseconds)+tseconds;
         rminutes = rminutes-1;
         if (rminutes<0) {
            rhours = rhours-1;
            rminutes = 60+rminutes;
            if (rhours<0) {
               rday = rday-1;
               rhours = 24+rhours;
               if (rday<0) {
                  rmonth = rmonth-1;
                  rday = Number(ndays)+Number(rday);
                  if (rmonth<0) {
                     ryear = ryear-1;
                     rmonth = 12+rmonth;
                  }
               }
            }
         }
      }
      // Countdown Checker
      if (ryear<0) {
         disyear = 0;
         dismonth = 0;
         disday = 0;
         dishours = 0;
         disminutes = 0;
         disseconds = 0;
         discountdown = "no";
         this.play();
         countdown = "no";
      } else {
         // Update Clock Check
         if (ryear ne year) {
            year = ryear;
            if (year<10) {
               this.years.years.disyear = "0"+year;
            } else {
               this.years.years.disyear = year;
            }
            this.years.play();
         }
         if (rmonth ne month) {
            month = rmonth;
            if (month<10) {
               this.months.months.dismonth = "0"+month;
            } else {
               this.months.months.dismonth = month;
            }
            this.months.play();
         }
         if (rday ne day) {
            day = rday;
            if (day<10) {
               this.days.days.disday = "0"+day;
            } else {
               this.days.days.disday = day;
            }
            this.days.play();
         }
         if (rhours ne hours) {
            hours = rhours;
            if (hours<10) {
               this.hour.hour.dishours = "0"+hours;
            } else {
               this.hour.hour.dishours = hours;
            }
            this.hour.play();
         }
         if (rminutes ne minutes) {
            minutes = rminutes;
            if (minutes<10) {
               this.minute.minute.disminutes = "0"+minutes;
            } else {
               this.minute.minute.disminutes = minutes;
            }
            this.minute.play();
         }
         if (rseconds ne seconds) {
            seconds = rseconds;
            if (seconds<10) {
               this.second.second.disseconds = "0"+seconds;
            } else {
               this.second.second.disseconds = seconds;
            }
            this.second.play();
         }
      }
   }
}

Por principe86

3 de clabLevel



 

msie8
Citar            
MensajeEscrito el 17 Ago 2009 02:22 pm
Hola principe86

la verdad que no soy muy weno con esto del AS pero quiza esto te de algunas ideas, yo hice un codigo para traer un texto desde un archivo .txt hacia un cuandro de texto en flash, esto podria servirte para lo que quieres...te explico como lo hice.

en el frame 1 colocque un boton con nombre de instancia "boton_txt" y arribita un cuandro de texto dinamico con nombre de instancia "campo_txt", luego dentro dela programacion en el primer fotograma coloque lo siguiente:

Código :

var texto_lv:LoadVars = new LoadVars();
texto_lv.onLoad = function(succesfull:Boolean){
   boton_txt.onPress = function(event){
      campo_txt.text = texto_lv.texto;
   }
}

texto_lv.load("archivo_txt.txt");


de ahi una vez compilado el .fla creas una archivo de texto en la misma carpeta, en este caso lo llame "archivo_txt.txt" y dentro se coloca lo siguiente:

Código :

&texto= Mi texto


entonces cuando ejecutes el archivo flash, apareceran el boton y el cuadro de texto vacion, y al oprimir el boton, aparecerá dentro del cuadro de texto la frase "Mi texto".

quiza asi puedas ayudarte a cargar el numero de reinicio desde un txt como mencionas para que no tengas que haer tanto movimiento, espero te sirva

Un saludo

Por loboblanco

74 de clabLevel



 

msie7

 

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