# This XML loader stuff is KILLING ME!

**URL:** <https://forum.kirupa.com/t/this-xml-loader-stuff-is-killing-me/246504>\
**Category:** flash\
**Created:** [December 11, 2007, 7:07pm UTC](https://forum.kirupa.com/t/this-xml-loader-stuff-is-killing-me/246504 "2007-12-11T19:07:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![notSoMuch](https://avatars.discourse-cdn.com/v4/letter/n/a87d85/32.png) [@notSoMuch](https://forum.kirupa.com/u/notSoMuch)\
**Post date:** [December 11, 2007, 7:07pm UTC](https://forum.kirupa.com/t/this-xml-loader-stuff-is-killing-me/246504/1 "2007-12-11T19:07:55Z")

</div>

seriously, I may actually die from trying to get this to work.  
I have been copying and pasting code for two days (again), and I can’t get this f_ **ing thing to work. I have been threatening to punch my computer in the f** _ing face. I know it’s not his fault, poor thing.

There are tutorials, threads, posts, discussions, etc, etc, about using XML to load images into a gallery. I cant get it. My most recent dead end started here:

[kirupaForum](http://www.kirupa.com/forum/showthread.php?t=263722&goto=nextoldest)

It now looks like this:

> 

import flash.display._;  
import flash.events._  
import flash.display.Loader;  
import flash.display.LoaderInfo;

var images\_list:Array = new Array();  
var images\_count:int = 0;  
var loaded:int = 0;  
var loaded\_filesize:int = 0;

//Create the loader, set dataFormat to text  
//and listen when data is loaded  
var xmlString:URLRequest = new URLRequest(“images.xml”);  
var xmlLoader:URLLoader = new URLLoader()  
xmlLoader.dataFormat = URLLoaderDataFormat.TEXT  
xmlLoader.addEventListener(Event.COMPLETE, onImagesXMLLoadComplete)  
xmlLoader.load(xmlString);

function onImagesXMLLoadComplete(ev:Event):void  
{  
trace(“Parsing XML…”);  
try  
{  
//Convert the downloaded text into an XML  
var myXML:XML = new XML(ev.target.data)  
var list:XMLList = myXML…image;  
this.images\_count = list.length();  
for(var i=0; i\<this.images\_count; i++)  
{  
this.images\_list.push(new Array(list\*.filename, list\*.caption));  
}  
trace(this.images\_list);  
this.display\_first\_image();  
}  
catch (e:TypeError)  
{  
//Could not convert the data, probably  
//because is not formated correctly  
trace(“Could not parse the XML”)  
trace(e.message)  
}

}

/////////////////////////////////////

prev\_btn.addEventListener(MouseEvent.CLICK, onPrevButtonClickEvent);  
next\_btn.addEventListener(MouseEvent.CLICK, onNextButtonClickEvent);

function onPrevButtonClickEvent(e:Event):void  
{  
trace(“previous btn clicked”);  
}

function onNextButtonClickEvent(e:Event):void  
{  
/\* if (p\<(total-1)) {  
p++;  
if (loaded == filesize) {  
picture.\_alpha = 0;  
picture.loadMovie(image[p], 1);  
desc\_txt.text = description[p];  
picture\_num();  
}  
}  
\*/  
trace(“next btn clicked”);  
}

this.addEventListener(Event.ENTER\_FRAME, onEnterFrameEvent);

function onEnterFrameEvent(e:Event):void  
{  
/\* this.filesize = Stage.loaderInfo.bytesTotal();  
this.loaded\_filesize = Stage.loaderInfo.bytesLoaded();  
preloader.\_visible = true;  
if (this.loaded\_filesize != this.filesize) {  
preloader.preload\_bar.\_xscale = (this.loaded\_filesize / this.filesize) \* 100;  
} else {  
preloader.\_visible = false;  
if (image.\_alpha \< 100) {  
image.\_alpha += 10;  
}  
}\*/  
}

function display\_first\_image():void  
{  
trace(“loading …” + this.images\_list[0][0]);

```
//if (this.loaded_filesize == this.filesize)
//{
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderCompleteEvent); 
    //loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInitEvent);
    //loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
    var request:URLRequest = new URLRequest(this.images_list[0][0]);
    loader.load(request);
    image.addChild(loader);
    trace(stage.stageHeight);
    image.x = 0;
    image.y = 0;
//}

```

}

function onLoaderCompleteEvent(e:Event):void  
{  
trace(“Loading completed…Resizing…”);  
// create a reference to the payload for easy coding…  
var thatpic:Bitmap = e.target.content;  
image.scaleY = image.scaleX;  
// either…  
image.width = 300;  
[//image.height](https://image.height) = 300;  
// or this will work…  
[//thatpic.width](https://thatpic.width) = 300;  
[//thatpic.height](https://thatpic.height) = 300;  
}

my XML, so far looks like this, which I demonstrate because maybe that’s the problem, ali.jpg and jimi.jpg are in the same folder as my broken swf and fla:

> 

\<?xml version=“1.0” encoding=“utf-8” standalone=“yes”?\>  
\<images\>  
\<pic\>  
\<image\>“ali.jpg”\</image\>  
\<caption\>Kresge\</caption\>  
\</pic\>  
\<pic\>  
\<image\>“jimi.jpg”\</image\>  
\<caption\>Media Lab\</caption\>  
\</pic\>  
\<pic\>  
\<image\>[http://www.kirupa.com/developer/mx2004/pg/stata.jpg&lt;/image&gt](http://www.kirupa.com/developer/mx2004/pg/stata.jpg&lt;/image&gt);  
\<caption\>Stata Center\</caption\>  
\</pic\>  
\<pic\>  
\<image\>[http://www.kirupa.com/developer/mx2004/pg/stata\_lobby.jpg&lt;/image&gt](http://www.kirupa.com/developer/mx2004/pg/stata_lobby.jpg&lt;/image&gt);  
\<caption\>Stata Lobby\</caption\>  
\</pic\>  
\<pic\>  
\<image\>[http://www.kirupa.com/developer/mx2004/pg/construction.jpg&lt;/image&gt](http://www.kirupa.com/developer/mx2004/pg/construction.jpg&lt;/image&gt);  
\<caption\>Construction\</caption\>  
\</pic\>  
\<pic\>  
\<image\>[http://www.kirupa.com/developer/mx2004/pg/dome.jpg&lt;/image&gt](http://www.kirupa.com/developer/mx2004/pg/dome.jpg&lt;/image&gt);  
\<caption\>The Dome\</caption\>  
\</pic\>  
\<pic\>  
\<image\>[http://www.kirupa.com/developer/mx2004/pg/structure.jpg&lt;/image&gt](http://www.kirupa.com/developer/mx2004/pg/structure.jpg&lt;/image&gt);  
\<caption\>Structure\</caption\>  
\</pic\>  
\</images\>

By the way, I have tried with and without quotes for the jpgs, but they only worked as well as the rest of the crap I’ve been doing for two days.

I want to be able to load images, hopefully one day soon with a preloader, which will probably cost me another 3-5 days to work out, into an image gallery when the user clicks on thumbnails.

The tutorial for XML Photo Gallery is EXCELLENT for MX, but for AS3, I’m definitely not smart enough to convert it all.

HELP!:wasted:
