xml image gallery
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
use the trace() function to pinpoint your first error (unless flash displays an error message when you publish your swf).
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
what is misImagenes.@CHICA?
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Dear Kglad.
where i put the trace function?
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
you don't see any trace output?
Copy link to clipboard
Copied
No trace output. Only errors
Copy link to clipboard
Copied
private var urlChicas:URLRequest;
should be:
private var urlChicas:String;
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
any suggestion to make work the code?
Copy link to clipboard
Copied
use the code i suggested in my previous message.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
Dear Kglad
Finally no errors came, but the images could be loaded : (
in
Copy link to clipboard
Copied
what's the following reveal:
private function listaChicas(e:Event):void{
var chica:Loader = Loader(e.target.loader);
contiene.addChild(chica);
trace(chica.stage);
}
Copy link to clipboard
Copied
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()


-
- 1
- 2