Comunidad de diseño web y desarrollo en internet online

Problema setInterval (en slideshow) en servidor.

Citar            
MensajeEscrito el 18 Dic 2008 06:51 pm
Hola muy buenas,
Buscando cómo hacer un slideshow encontré éste: http://www.after-hours.org/2006/06/26/flas-8-slideshow/
Bueno, lo he estado adaptando para que pueda tener botones que seleccionen las imágenes que se desean ver pero me surge un problema cuando lo subo a un servidor.
El problema surge que se va acelerando, como si el clearInterval no hiciese caso y el setInterval se acumulase.

Esto ya se comentó en el tutorial pero no hubo respuesta. Y la verdad , no tengo ni idea de que puede ser, la verdad.

He probado con un setTimeout y no sé si la clave puede estar en usar además clearTimeout, pero la verdad es que no sé muy bien cómo. Evidentemente esto pasa por no tener ni idea de programar. Os dejo el enlace donde lo he subido para que podais apreciar lo que ocurre.

http://tinyurl.com/4zv74v

Espero que le podáis echar al menos un vistazo.

Aqui está el .fla, para facilitar la labor.
http://snurl.com/8u4p2

Muchas gracias,

Susana

Por Hirmine

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 18 Dic 2008 06:56 pm
Os dejo el código. Es posible que haya cosas que no tengan sentido (al menos he visto 2 lineas), pero he hehco tantas pruebas que se me han quedado ahí. Creo que no afectan a la funcionalidad del sitio. Perdón las molestias,
Susana

Código :

Stage.align = "TL";
Stage.scaleMode = "noScale";
trace(Stage.height);
import mx.utils.Delegate;



//-------------------------------------------------------------------
// importar clase tween
//-------------------------------------------------------------------
import mx.transitions.Tween;
import mx.transitions.easing.*;
//-------------------------------------------------------------------
// declarar variables
//-------------------------------------------------------------------
var my_xml:XML = new XML ();
my_xml.ignoreWhite = true;
var time:Number = 5;
var urls:Array = new Array ();
var prevMovie:String;
var index:Number = 0;
var depth:Number = 0;
var num_fotos = 10;
//-------------------------------------------------------------------
// cargar XML
//------------------------------------------------------------------



doInterval = function () {
   intervalId = setInterval (_root, "loadImages", time * 1000);
   updateAfterEvent();
};
/*doInterval = function () {
   intervalId = setInterval (Delegate.create(_root,intervalId), "loadImages", time * 1000);
};
*/

my_xml.onLoad = function (success) {
   if (success) {
      for (var i = 0; i < this.firstChild.childNodes.length; i++) {
         urls.push (this.firstChild.childNodes[i].attributes.url);
      }
      trace("longitud del xml " + my_xml.firstChild.childNodes.length);
      loadImages ();
      doInterval ();
      trace(intervalId)
      /*colocacion de botones*/
      

      //duplicateMovieClip(btn00_mc, "btn2_mc", 7);
      //btn2_mc._y = 550;
      //btn2_mc._x = ((Stage.width/(my_xml.firstChild.childNodes.length + 1) - btn00_mc._width) / 2) + Stage.width/(my_xml.firstChild.childNodes.length + 1);
      
      //intervalId = setInterval (_root, "loadImages", time * 1000);
   } else {
      trace ("Error al cargar el archivo");
   }
};
//
my_xml.load ("data.xml");

//-------------------------------------------------------------------
// procesar registros

loadImages = function ():Void {
   prevMovie = currentMovie;
   currentMovie = this.createEmptyMovieClip ("currentMovie" + depth, depth);
   var mclListener:Object = new Object ();
   lop;
   mclListener.onLoadComplete = function (target_mc:MovieClip) {
      var tween_handler:Object = new Tween (target_mc, "_alpha", Strong.easeOut, 0, 100, 3, true);
      tween_handler.onMotionFinished = function () {
         unloadMovie (prevMovie);
      };
   };
   var movieClipLoader:MovieClipLoader = new MovieClipLoader ();
   movieClipLoader.addListener (mclListener);
   movieClipLoader.loadClip (urls[index], currentMovie);
   index == urls.length - 1 ? index = 0 : index++;
   depth++;
};

      for(i = 0;i<= num_fotos; i++) {
         
         duplicateMovieClip(btn00_mc, i, this.getNextHighestDepth());
         //trace("valor de i " + i);
         this[i]._x =  (Stage.width/num_fotos - btn00_mc._width) / 2 + (Stage.width/num_fotos)*(i-1);
         this[i]._y = 550;
         //trace(this[i]._name);
/*         this["btn" + i + "_mc"].onRelease = function () {
            trace("hola " + this._name)
            clearInterval (intervalId);
            trace("desactivado " + intervalId)
            _parent.intervalId = undefined;
            peli = "img0" + i +".jpg";
            trace(i);
            loadMovie(peli, _root.currentMovie);
            setTimeout(doInterval, 2000, 0);
            
            
            }*/
      
         }
         
for(k=1; k<=num_fotos; k++) {

   var my_timedProcess:Number = setTimeout(my_delayedFunction, 2000, "two second delay");
   
      this[k].onRelease = function () {
         unloadMovie(_root.currentMovie);
            //trace("hola " + this._name)
            clearInterval (intervalId);
            //trace("desactivado " + intervalId)
            _parent.intervalId = undefined;
            peli = "img0" + this._name +".jpg";
            //trace(peli )
            loadMovie(peli, _root.currentMovie);
            setTimeout(doInterval, 2000, 0);
      }
} 
[/code]

Por Hirmine

1 de clabLevel



 

firefox
Citar            
MensajeEscrito el 19 Dic 2008 07:45 am
prueba poniedo esto en la funcion doInterval

Código :

doInterval = function () {
   clearInterval(intervalId);
   intervalId = setInterval (_root, "loadImages", time * 1000);
   updateAfterEvent();
};

Por LongeVie

Claber

1741 de clabLevel

1 tutorial

Genero:Masculino  

En un lugar, re moto.

firefox
Citar            
MensajeEscrito el 19 Dic 2008 12:25 pm

LongeVie escribió:

prueba poniedo esto en la funcion doInterval

Código :

doInterval = function () {
   clearInterval(intervalId);
   intervalId = setInterval (_root, "loadImages", time * 1000);
   updateAfterEvent();
};


Muchas gracias, funciona!!

Y de paso os dejo los archivos completos del slideshow por si os interesan.
No es la versión definitiva pero esta (más o menos) funcional.
Faltaría poner cada foto en la miniatura y arreglar un par de cosas.

http://snurl.com/8vn0q

Y el código completo por si alguien lo quiere

Código :

Stage.align = "TL";
Stage.scaleMode = "noScale";
trace(Stage.height);
import mx.utils.Delegate; 



//-------------------------------------------------------------------
// importar clase tween
//-------------------------------------------------------------------
import mx.transitions.Tween;
import mx.transitions.easing.*;
//-------------------------------------------------------------------
// declarar variables
//-------------------------------------------------------------------
var my_xml:XML = new XML ();
my_xml.ignoreWhite = true;
var time:Number = 5;
var urls:Array = new Array ();
var prevMovie:String;
var index:Number = 0;
var depth:Number = 0;
var num_fotos = 10;
//-------------------------------------------------------------------
// cargar XML
//-------------------------------------------------------------------



doInterval = function () {
   clearInterval(intervalId);
   intervalId = setInterval (_root, "loadImages", time * 1000);
   updateAfterEvent();
};
/*doInterval = function () {
   intervalId = setInterval (Delegate.create(_root,intervalId), "loadImages", time * 1000);
};
*/

my_xml.onLoad = function (success) {
   if (success) {
      for (var i = 0; i < this.firstChild.childNodes.length; i++) {
         urls.push (this.firstChild.childNodes[i].attributes.url);
      }
      trace("longitud del xml " + my_xml.firstChild.childNodes.length);
      loadImages ();
      doInterval ();
      trace(intervalId)
      /*colocacion de botones*/
      

      //duplicateMovieClip(btn00_mc, "btn2_mc", 7);
      //btn2_mc._y = 550; 
      //btn2_mc._x = ((Stage.width/(my_xml.firstChild.childNodes.length + 1) - btn00_mc._width) / 2) + Stage.width/(my_xml.firstChild.childNodes.length + 1);
      
      //intervalId = setInterval (_root, "loadImages", time * 1000);
   } else {
      trace ("Error al cargar el archivo");
   }
};
//
my_xml.load ("data.xml");

//-------------------------------------------------------------------
// procesar registros

loadImages = function ():Void {
   prevMovie = currentMovie;
   currentMovie = this.createEmptyMovieClip ("currentMovie" + depth, depth);
   var mclListener:Object = new Object ();
   
   mclListener.onLoadComplete = function (target_mc:MovieClip) {
      var tween_handler:Object = new Tween (target_mc, "_alpha", Strong.easeOut, 0, 100, 3, true);
      tween_handler.onMotionFinished = function () {
         unloadMovie (prevMovie);
      };
   };
   var movieClipLoader:MovieClipLoader = new MovieClipLoader ();
   movieClipLoader.addListener (mclListener);
   movieClipLoader.loadClip (urls[index], currentMovie);
   index == urls.length - 1 ? index = 0 : index++;
   depth++;
};

      for(i = 0;i<= num_fotos; i++) {
         
         duplicateMovieClip(btn00_mc, i, this.getNextHighestDepth());
         //trace("valor de i " + i);
         this[i]._x =  (Stage.width/num_fotos - btn00_mc._width) / 2 + (Stage.width/num_fotos)*(i-1);
         this[i]._y = 550;
         //trace(this[i]._name);
/*         this["btn" + i + "_mc"].onRelease = function () {
            trace("hola " + this._name)
            clearInterval (intervalId);
            trace("desactivado " + intervalId)
            _parent.intervalId = undefined;
            peli = "img0" + i +".jpg";
            trace(i);
            loadMovie(peli, _root.currentMovie);
            setTimeout(doInterval, 2000, 0);
            
            
            }*/
      
         } 
         
for(k=1; k<=num_fotos; k++) {

   
   
      this[k].onRelease = function () {
         unloadMovie(_root.currentMovie);
            //trace("hola " + this._name)
            clearInterval (intervalId);
            //trace("desactivado " + intervalId)
            _parent.intervalId = undefined;
            peli = "img0" + this._name +".jpg";
            //trace(peli )
            loadMovie(peli, _root.currentMovie);
            setTimeout(doInterval, 1000, 0);
      }
}
      
      

Por Hirmine

1 de clabLevel



 

firefox

 

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