
Originally Posted by
nate51
The output window displayed this.
"images/undefined"
As expected. See, the scope of the XML object doesn't go beyond the object itself. That's why in my example you see the use of arrays. What is the best thing to do when working with XML in a robust application like this, is to add the data to variable arrays or other variables so that you can manipulate the data afterwards.
You're doing everything within the onLoad() event. There is nothing wrong with it, but for clarity of code I suggest you move the code outside. Also, you're declaring a lot of variables that don't come into use. Lastly, you're calling a "title" attribute from your XML which doesn't exist.
I'm assuming you'll add the title in -- otherwise your caption in Lightbox will read "undefined";
So, anyway...cleaning up your code, I get this:
Code:
var xml:XML = new XML();
xml.ignoreWhite = true;
var totalImages:Number = new Number();
var count:Number = 0; // Variable that counts how many movieclips have rendered thus far
var yPos:Number = 30; // Initial _y coordinate of the first row
var spacing:Number = 55;
xml.onLoad = function(success) {
if (success) {
totalImages = this.firstChild.childNodes.length;
loadImages();
}
};
function loadImages() {
for (i=0; i<totalImages; i++) {
var thmbPath:String = xml.firstChild.childNodes[i].attributes.thmb;
var holder:MovieClip = this.createEmptyMovieClip("holder"+i, this.getNextHighestDepth());
var thumbnail:MovieClip = holder.createEmptyMovieClip("thumb", 1);
holder.id = i;
thumbnail.loadMovie(thmbPath);
holder.onRelease = function() {
trace("javascript:LightboxDelegate('" + xml.firstChild.childNodes[this.id].attributes.src + "','" + xml.firstChild.childNodes[this.id].attributes.title + "')");
getURL("javascript:LightboxDelegate('" + xml.firstChild.childNodes[this.id].attributes.src + "','" + xml.firstChild.childNodes[this.id].attributes.title + "')");
}
if (count == 8) { // if count = 8, we're at the end of the row
count = 0; // reset count to 0
yPos = yPos + 70; // incease the _y coordinate for the next row (100 = height of element plus padding)
}
holder._x = count*spacing // set _x coordinate
holder._y = yPos; // set _y coordinate
count++; // increase count by 1
};
}
xml.load("wedding.xml");
When you click a thumbnail, it'll trace the LightboxDelegate call (and probably launch a blank browser window). When you embed it, it should work as intended with Lightbox++.
HTH
Bookmarks