Photo gallery easy question?

I’ve been trying to customize the photo gallery tut to incorporate an xml doc. (I’ve looked at the macromedia xml gallery tut but I would like my pics to fade in and out).

My question is:

How can I make my image array available to the other code functions if it is created within an initial xml function, rather than as a global list?

i.e.

function startSlideshow(){
this.pArray = new Array();
for(i = 0; i < root.childNodes.length; i++){
this.pArray* = root.childNodes*.attributes.src;
}
}

rather than:

this.pArray = “image0.jpg”, “image1.jpg”, “image2.jpg”, …etc.

I’d be happy to supply the full code if it will make more sense! Thanks for your time…

*Originally posted by new2mx *
How can I make my image array available to the other code functions if it is created within an initial xml function, rather than as a global list?
I don’t understand the question. Do you have problems parsing the data, putting it in the array or is it something else?

pom :asian:

Firstly, thanks ilyaslamasse for your reply.

I have the array from the xml, but because it is made within a function, when I click the next button to forward the slideshow the ‘changePhoto’, ‘loadPhoto’ and other functions don’t know that an array exists.

In the original tut, the image array is made outside a function so the array and so its contents exists globally to all functions.

My problem is making the image array and its contents available to the ‘changePhoto’, ‘loadPhoto’, etc. functions. I think this is an array parsing problem like you suggested.

Hope this makes more sense, if not please let me know and I’ll post code.

Happily the prob was one of those stoopid typo things. Just needed to reference the array in the right way (was this.pArray, just needed to be pArray).

Thanks again tho for replying, ilyaslamasse. Cheers.

I was wondering: could you post your flash file, and the XML file, or at least the structure or the code? I’d like to have a look at it. If it’s not too much trouble or confidential, of course…

pom :slight_smile:

sure. it’s in its earliest form tho - now that i have the basic thing working i’ll have to tweak it lots!

a/s code (adapted from kirupa tut):


this_xml = new XML();
this_xml.onLoad = startSlideShow;
this_xml.load("photos.xml");
this_xml.ignoreWhite = true;
//
// Show the first slide and intialize variables
function startSlideShow(success) {
	if (success == true) {
		root = this_xml.firstChild;
		pArray = new Array();
		for(i = 0; i < root.childNodes.length; i++){
			pArray* = root.childNodes*.attributes.src;
		}
		//trace(pArray.length)
		loadMovie(pArray[0], _root.photo);
	}
}

this.fadeSpeed = 20;
this.pIndex = 0;

MovieClip.prototype.changePhoto = function(d) {
	// make sure pIndex falls within pArray.length
	this.pIndex = (this.pIndex+d)%this.pArray.length;
	if (this.pIndex<0) {
		this.pIndex += this.pArray.length;
	}
	this.onEnterFrame = fadeOut;
};
MovieClip.prototype.fadeOut = function() {
	if (this.photo._alpha>this.fadeSpeed) {
		this.photo._alpha -= this.fadeSpeed;
	} else {
		this.loadPhoto();
	}
};
MovieClip.prototype.loadPhoto = function() {
	// specify the movieclip to load images into
	var p = _root.photo;
	//------------------------------------------
	p._alpha = 0;
	p.loadMovie(this.pathToPics+this.pArray[this.pIndex]);
	this.onEnterFrame = loadMeter;
};
MovieClip.prototype.loadMeter = function() {
	var i, l, t;
	l = this.photo.getBytesLoaded();
	t = this.photo.getBytesTotal();
	if (t>0 && t == l) {
		this.onEnterFrame = fadeIn;
	} else {
		trace(l/t);
	}
};
MovieClip.prototype.fadeIn = function() {
	if (this.photo._alpha<100-this.fadeSpeed) {
		this.photo._alpha += this.fadeSpeed;
	} else {
		this.photo._alpha = 100;
		this.onEnterFrame = null;
	}
};

the xml doc has just a root tag called photos and childNodes called image, with an attribute of source.

hope this is of use - i’d appreciate on your feedback if you can improve the code any.

cheers

ps apols for lack of formatting and weird icon which appears mid code.

I formatted it, if you don’t mind. And also, for the record, and tell me if I’m wrong :), your XML structures shoul look like

< photo >
  < image >1.jpg< /image >
  < image >2.jpg< /image >
  < image >3.jpg< /image >
< /photo >

By the way, you had an error with your array because if you use this.pArray, the keyword this. makes the array relative to the object that calls the function, here your XML object. That’s why it wasn’t were it was supposed to be: in the _root.

Cheers! (could you rate this thread please?)

pom :asian: