Comunidad de diseño web y desarrollo en internet online

Precarga multiple

Citar            
MensajeEscrito el 20 Ago 2010 04:45 pm
Hola!!

estoy migrando de AS2 a AS3 y haciendo pruebas me he encontrado con un problema que no consigo resolver.

Estoy intentando crear una mini galería de 5 imágenes, pero no consigo que me cargue las imágenes dentro de las MC.

El código es este:

Código ActionScript :

package {
   import flash.display.Sprite;
   import flash.events.*;
   import flash.net.URLRequest;
   import flash.net.URLLoader;
   import flash.display.Loader;
   import flash.net.*;


   public class galeria extends Sprite {

      var img0:String = "img0.jpg";
      var img1:String = "img1.jpg";
      var img2:String = "img2.jpg";
      var img3:String = "img3.jpg";
      var img4:String = "img4.jpg";


      public function galeria() {
         var loader:Loader = new Loader();
         loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imagenError);
         loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imagenProgreso);
         loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imagenCargada);

         var boton:bt;
         for (var i:uint=0; i<5; i++) {
            boton = new bt();
            boton.x = i * boton.width;
            addChild(boton);
            boton.name = "mc" + i;
            loader.load( new URLRequest(this["img"+i]));

         }

      }

      private function imagenCargada(e:Event):void {
         trace("completeHandler: " + e.target.content);
         boton.addChild(e.target.content); 
      }
      private function imagenError(e:IOErrorEvent):void {
         trace("ioErrorHandler: " + e);
      }

      private function imagenProgreso(e:ProgressEvent):void {
         trace("progressHandler: bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal);
      }


   }

}


El error me lo da en la línea "boton.addChild(e.target.content); ", me dice acceso a una propiedad Boton no definida.

Gracias de antemano por la ayuda!!!!

Por zuk

4 de clabLevel



Genero:Masculino  

Barcelona

firefox
Citar            
MensajeEscrito el 20 Ago 2010 05:02 pm
BuenAS:

Código ActionScript :

package { 
   import flash.display.Loader;
   import flash.display.Sprite;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.ProgressEvent;
   import flash.net.*;
   import flash.net.URLLoader;
   import flash.net.URLRequest;
   
   
   public class galeria extends Sprite { 
      var img0:String = "img0.jpg"; 
      var img1:String = "img1.jpg"; 
      var img2:String = "img2.jpg"; 
      var img3:String = "img3.jpg"; 
      var img4:String = "img4.jpg"; 
      
      public function galeria() { 
         
         var loader:Loader; 
         var boton:Sprite; 
         for (var i:uint=0; i<5; i++) {
            loader = new Loader(); 
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, imagenError); 
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imagenProgreso); 
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imagenCargada);
            boton = new Sprite(); 
            boton.x = i * boton.width;
            boton.name = "mc" + i; 
            loader.load( new URLRequest(this["img"+i.toString()])); 
            boton.addChild(loader);
            addChild(boton);
         } 
         
      } 
      
      private function imagenCargada(e:Event):void { 
         trace("completeHandler: " + e.target.content); 
         //boton.addChild(e.target.content);  
      } 
      private function imagenError(e:IOErrorEvent):void { 
         trace("ioErrorHandler: " + e); 
      } 
      
      private function imagenProgreso(e:ProgressEvent):void { 
         trace("progressHandler: bytesLoaded=" + e.bytesLoaded + " bytesTotal=" + e.bytesTotal); 
      } 
      
      
   } 
   
}


Sería recomendable meter los nombres en un array más que en variables individuales. Sólo he quitado los errores; yo me plantearía otro enfoque a la hora de hacerlo.

Un saludo.

Por Lukánicos

Claber

468 de clabLevel



Genero:Masculino  

chrome
Citar            
MensajeEscrito el 20 Ago 2010 05:03 pm
---esto... te he sustituido bt() por Sprite() y se me ha olvidado cambiarlo al pegar el código.

Por Lukánicos

Claber

468 de clabLevel



Genero:Masculino  

chrome
Citar            
MensajeEscrito el 21 Ago 2010 08:53 am
Hola Lukánicos,

gracias por tu respuesta!!! respecto a las imágenes en un array está claro, y ya que lo comentas si no es mucho pedir me gustaría conocer tu enfoque.

Por zuk

4 de clabLevel



Genero:Masculino  

Barcelona

firefox

 

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