Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

xml image gallery

Community Beginner ,
Jan 03, 2011 Jan 03, 2011

Hi everyone

im triyng to upload using an external xml some images but it doesnt work

could some one please help me with this;

here is the code:

package {  

import flash.display.*;  

import flash.events.*; 

import flash.net.*;    


public class xml extends Sprite {         

private var imagenes:XML;         

private var cargaImagenes:URLLoader;    

private var cargaChicas:URLLoader;    

private var urlChicas:URLRequest;     

private var columnas:Number;    

private var miX:Number;    

private var miY:Number;    

private var chicaAncho:Number;    

private var chicaAlto:Number;    

private var misImagenes:XMLList;   

private var miTotal:Number;        

private var contiene:MovieClip;         


     public function xml ( ) {             

     var cargaXML:URLRequest = new URLRequest("xml/prueba.xml");      

     cargaImagenes = new URLLoader( );     

      cargaImagenes.addEventListener(Event.COMPLETE, procesaXML);      

     cargaImagenes.load(cargaXML);           

     }        


      private function procesaXML(e:Event):void {                   

      imagenes = new XML(e.target.data);                

     columnas = imagenes.@COLUMNAS;        

     miX = imagenes.@POSICIONX;       

      miY = imagenes.@POSICIONY;        

     chicaAncho = imagenes.@ANCHO;        

     chicaAlto = imagenes.@ALTO;        

     misImagenes = imagenes.IMAGEN;       

      miTotal = misImagenes.length();                 


     contenedor();       

      llamaChicas();                                       

     }    


     private function contenedor():void {        

     contiene = new MovieClip();        

     contiene.x = miX;        

     contiene.y = miY;        

     addChild(contiene);    

     }      

    

      private function llamaChicas():void {        

          for (var i:Number = 0; i < miTotal; i++){             

               var urlChicas = misImagenes.@CHICA;          

               var cargaChicas:Loader = new Loader();                


               cargaChicas.load(new URLRequest(urlChicas));                

               cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                       

          }  

     }        



        private function listaChicas(e:Event):void{            

          var chica:Loader = Loader(e.target.loader);                     

          contiene.addChild(chica);        

     }

  }

}

TOPICS
ActionScript
2.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2011 Jan 03, 2011

use the trace() function to pinpoint your first error (unless flash displays an error message when you publish your swf).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 04, 2011 Jan 04, 2011

dear kaglad

yes an error occurs and it said in the compiler message board:

[warning]1008: variable 'urlChicas' has no type delcaration. (src/xml as:63)

the urlChicas is declarated as a private var before the class "xml"

and all supose to be in the right place XML and the JPG

here is the XML

<?xml version="1.0" encoding="utf-8"?>   

<prueba COLUMNAS="5" POSICIONX="30" POSICIONY="30" ANCHO="100" ALTO="100">           

<IMAGEN GRANDE="uno.jpg" CHICA="uno.jpg" />           

<IMAGEN GRANDE="dos.jpg"  CHICA="dos.jpg" />           

<IMAGEN GRANDE="tres.jpg" CHICA="tres.jpg" />           

</prueba>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2011 Jan 04, 2011

to remove that warning use the following.  then use the trace() function (if there are no more errors).


package {  

import flash.display.*;  

import flash.events.*; 

import flash.net.*;    


public class xml extends Sprite {         

private var imagenes:XML;         

private var cargaImagenes:URLLoader;    

private var cargaChicas:URLLoader;    

private var urlChicas:URLRequest;     

private var columnas:Number;    

private var miX:Number;    

private var miY:Number;    

private var chicaAncho:Number;    

private var chicaAlto:Number;    

private var misImagenes:XMLList;   

private var miTotal:Number;        

private var contiene:MovieClip;         


     public function xml ( ) {             

     var cargaXML:URLRequest = new URLRequest("xml/prueba.xml");      

     cargaImagenes = new URLLoader( );     

      cargaImagenes.addEventListener(Event.COMPLETE, procesaXML);      

     cargaImagenes.load(cargaXML);           

     }        


      private function procesaXML(e:Event):void {                   

      imagenes = new XML(e.target.data);                

     columnas = imagenes.@COLUMNAS;        

     miX = imagenes.@POSICIONX;       

      miY = imagenes.@POSICIONY;        

     chicaAncho = imagenes.@ANCHO;        

     chicaAlto = imagenes.@ALTO;        

     misImagenes = imagenes.IMAGEN;       

      miTotal = misImagenes.length();                 


     contenedor();       

      llamaChicas();                                       

     }    


     private function contenedor():void {        

     contiene = new MovieClip();        

     contiene.x = miX;        

     contiene.y = miY;        

     addChild(contiene);    

     }      

    

      private function llamaChicas():void {        

          for (var i:Number = 0; i < miTotal; i++){             

               urlChicas = misImagenes.@CHICA;          

               var cargaChicas:Loader = new Loader();                


               cargaChicas.load(new URLRequest(urlChicas));                

               cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                       

          }  

     }        



        private function listaChicas(e:Event):void{            

          var chica:Loader = Loader(e.target.loader);                     

          contiene.addChild(chica);        

     }

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 04, 2011 Jan 04, 2011

I used

urlChicas = misImagenes.@CHICA;

and an error occurs in the line:


cargaChicas.load(new URLRequest(urlChicas));


[error] 1067: Implicit coercion of a value of type flash.net.URLRequest to unrelated type String (rec.xml.as:65)

the function si as follow;

private function llamaChicas():void {

         for (var i:Number = 0; i < miTotal; i++) {             

          urlChicas = misImagenes.@CHICA;          

          var cargaChicas:Loader = new Loader();               

          cargaChicas.load(new URLRequest(urlChicas));                

          cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                       

     } 

the error perists, its searching for a string but is a number...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2011 Jan 04, 2011

use the trace() function.  what's the following show:



package {  

import flash.display.*;  

import flash.events.*; 

import flash.net.*;    


public class xml extends Sprite {         

private var imagenes:XML;         

private var cargaImagenes:URLLoader;    

private var cargaChicas:URLLoader;    

private var urlChicas:URLRequest;     

private var columnas:Number;    

private var miX:Number;    

private var miY:Number;    

private var chicaAncho:Number;    

private var chicaAlto:Number;    

private var misImagenes:XMLList;   

private var miTotal:Number;        

private var contiene:MovieClip;         


     public function xml ( ) {             

     var cargaXML:URLRequest = new URLRequest("xml/prueba.xml");      

     cargaImagenes = new URLLoader( );     

      cargaImagenes.addEventListener(Event.COMPLETE, procesaXML);      

     cargaImagenes.load(cargaXML);           

     }        


      private function procesaXML(e:Event):void {                   

      imagenes = new XML(e.target.data);                

     columnas = imagenes.@COLUMNAS;        

     miX = imagenes.@POSICIONX;       

      miY = imagenes.@POSICIONY;        

     chicaAncho = imagenes.@ANCHO;        

     chicaAlto = imagenes.@ALTO;        

     misImagenes = imagenes.IMAGEN;       

      miTotal = misImagenes.length();                 


     contenedor();       

      llamaChicas();                                       

     }    


     private function contenedor():void {        

     contiene = new MovieClip();        

     contiene.x = miX;        

     contiene.y = miY;        

     addChild(contiene);    

     }      

    

      private function llamaChicas():void {        

          for (var i:Number = 0; i < miTotal; i++){             

               urlChicas = misImagenes.@CHICA;        

trace(urlChicas,urlChicas.length); 

               var cargaChicas:Loader = new Loader();                


               cargaChicas.load(new URLRequest(urlChicas));                

               cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                       

          }  

     }        



        private function listaChicas(e:Event):void{            

          var chica:Loader = Loader(e.target.loader);                     

          contiene.addChild(chica);        

     }

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 04, 2011 Jan 04, 2011

i used trace in the complier message windows appear

[error]1119 Access of possibly undefined property lenght thorugh a reference with a static type flash.net.URLRequest (src/xml.as:64)

[error]1067 implicit coercion of a value of type flash.display.Loader to an unrelated type Class (src/xml.as:65)

[error]1188 Illegal assigment to class Loader (src.sml.as:65)

[error]1067 Implicit coercion of a value of type flash.net.URLRequest to an unrelated type String (src/xml.as:66)

[error]1119 Access of possibly undefined property contentLoaderInfo through a reference with a static type flash.net.URLoader (src/xml.as:67)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2011 Jan 04, 2011

what is misImagenes.@CHICA?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 05, 2011 Jan 05, 2011

To retrive the URL of CHICA (XML DOCUMENT) and  store it in a local variable  called URLChicas. This variable is only used within the loop, so there  is no need to create it outside.  below is used to cycle through the elements in the XML file and it retrieves the actual URL by using the @ operator to get the value of that attribute:

CHICAS

var URLChicas = my_images.@CHICAS;

may be it had to be declare in other place?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2011 Jan 05, 2011

i don't know where that variable came from but you probably don't have that attribute assigned for all the nodes in your for-loop.  use the trace() function to see which i causes the failure.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2011 Jan 06, 2011

Dear Kglad.

where i put the trace function?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 06, 2011 Jan 06, 2011

use something like:

  private function llamaChicas():void {        

          for (var i:Number = 0; i < miTotal; i++){     

trace(i,misImagenes.@CHICA);       

               urlChicas = misImagenes.@CHICA;


               var cargaChicas:Loader = new Loader();                


               cargaChicas.load(new URLRequest(urlChicas));                

                cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE,  listaChicas);                                       

          }  

     }        

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 07, 2011 Jan 07, 2011

dear kglad,

i used the trace function, and  it seems that it is no recognizing the Loeader and contentLoaderInfo. Aby idea?

[error]1067 implicit coercion of a value of type flash.display.Loader to an unrelated type Class (src/xml.as:66)

[error]1188 Illegal assigment to class Loader (src.sml.as:66)

[error]1067 Implicit coercion of a value of type flash.net.URLRequest to an unrelated type String (src/xml.as:67)

[error]1119  Access of possibly undefined property contentLoaderInfo through a  reference with a static type flash.net.URLoader (src/xml.as:67)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 07, 2011 Jan 07, 2011

you don't see any trace output?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 09, 2011 Jan 09, 2011

No trace output. Only errors

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2011 Jan 09, 2011

private var urlChicas:URLRequest;  

should be:

private var urlChicas:String;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 09, 2011 Jan 09, 2011

I test before your suggestion but here is the error:

[error]1067 implicit coercion of a value of type flash.display.Loader to an unrelated type Class (src/xml.as:66)

[error]1188 Illegal assigment to class Loader (src.sml.as:66)

[error]1119   Access of possibly undefined property contentLoaderInfo through a   reference with a static type flash.net.URLoader (src/xml.as:67)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2011 Jan 09, 2011

use:


here is the code:

package {  

import flash.display.*;  

import flash.events.*; 

import flash.net.*;    


public class xml extends Sprite {         

private var imagenes:XML;         

private var cargaImagenes:URLLoader;    

private var cargaChicas:URLLoader;    

private var urlChicas:String;     

private var columnas:Number;    

private var miX:Number;    

private var miY:Number;    

private var chicaAncho:Number;    

private var chicaAlto:Number;    

private var misImagenes:XMLList;   

private var miTotal:Number;        

private var contiene:MovieClip;         


     public function xml ( ) {             

     var cargaXML:URLRequest = new URLRequest("xml/prueba.xml");      

     cargaImagenes = new URLLoader( );     

      cargaImagenes.addEventListener(Event.COMPLETE, procesaXML);      

     cargaImagenes.load(cargaXML);           

     }        


      private function procesaXML(e:Event):void {                   

      imagenes = new XML(e.target.data);                

     columnas = imagenes.@COLUMNAS;        

     miX = imagenes.@POSICIONX;       

      miY = imagenes.@POSICIONY;        

     chicaAncho = imagenes.@ANCHO;        

     chicaAlto = imagenes.@ALTO;        

     misImagenes = imagenes.IMAGEN;       

      miTotal = misImagenes.length();                 


     contenedor();       

      llamaChicas();                                       

     }    


     private function contenedor():void {        

     contiene = new MovieClip();        

     contiene.x = miX;        

     contiene.y = miY;        

     addChild(contiene);    

     }      

    

      private function llamaChicas():void {        

          for (var i:Number = 0; i < miTotal; i++){             

               urlChicas = misImagenes.@CHICA;          

            //  var cargaChicas:Loader = new Loader();    <- wrong            


               cargaChicas.load(new URLRequest(urlChicas));                

               cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                       

          }  

     }        



        private function listaChicas(e:Event):void{            

          var chica:Loader = Loader(e.target.loader);                     

          contiene.addChild(chica);        

     }

  }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 09, 2011 Jan 09, 2011

any suggestion to make work the code?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2011 Jan 09, 2011

use the code i suggested in my previous message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2011 Jan 11, 2011

i comment

private function llamaChicas():void {       

     for (var i:Number = 0; i < miTotal; i++) {     

      //  trace(i,misImagenes.@CHICA);                        

      urlChicas = misImagenes.@CHICA;                 

     //     var  cargaChicas:Loader = new Loader();               

     cargaChicas.load(new URLRequest(urlChicas));              

       cargaChicas.contentLoaderInfo.addEventListener(Event.COMPLETE, listaChicas);                                      

      }

}

and the following error appear:

[error]1119   Access of possibly undefined property contentLoaderInfo  through a   reference with a static type flash.net.URLoader  (src/xml.as:68)

the variables for that functions are

   private var cargaChicas:URLLoader;   

   private var urlChicas:String;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2011 Jan 11, 2011

that should be:


private function llamaChicas():void {       

     for (var i:Number = 0; i < miTotal; i++) {     

      //  trace(i,misImagenes.@CHICA);                        

      urlChicas = misImagenes.@CHICA;                 

     //     var  cargaChicas:Loader = new Loader();               

     cargaChicas.load(new URLRequest(urlChicas));              

       cargaChicas.addEventListener(Event.COMPLETE, listaChicas);                                      

      }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2011 Jan 11, 2011

Dear Kglad

Finally no errors came, but the images could be loaded : (

in

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2011 Jan 11, 2011

what's the following reveal:

   private function listaChicas(e:Event):void{            

          var chica:Loader = Loader(e.target.loader);                     

          contiene.addChild(chica);   

trace(chica.stage);    

     }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 22, 2011 Jan 22, 2011

sorry for the big delay. my machine crash, so i had to buy me a new one

i use what u said

trace(chica.stage); 

and these are the error the new .as classs is called "martARTader"

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at martARTadero/llamaChicas()

at martARTadero/procesaXML()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines