Photo Gallery with external files

I’m trying to make the Photo Gallery tutorial (http://www.kirupa.com/developer/mx/photogallery.htm) work using an imported .txt file to create my list of images. I can import the .txt file (myImages= “image0.jpg”, “image1.jpg”, “image2.jpg”) but I can’t figure out how to make Flash see it as an array rather than just a string of text.

My aim is to create a slideshow in which the image .jpgs and their names are both in easily updated in external files so I can add to the presentation without modifying the .swf file.

Any suggestions will be much appreciated.

Cheers,

Cliff

What exactly does the error says?

I tried it here and it’s working apart from 1 line:

loadMovie(this.pathToPics+this.pArray[0], _root.photo);

doesn’t work, cause at the moment it calls pArray, it doesn’t exists. Skip that line. If you want a picture at start, change the load text code like this:

pArray = new Array();
loadArray = new LoadVars();
loadArray.load("imageList.txt");
loadArray.onLoad = function(success) {
	if (success) {
		pArray = this.myImages.split(",");
		changePhoto(0);//added this one
	}
};

scotty(-:

Hi Scotty:

I found the problem. It was my mistake in the .txt file. My original .txt file was as follows: myImages=“image0.jpg”,“image1.jpg”,“image2.jpg”,“image3.jpg”,“image4.jpg”,“image5.jpg”,“image6.jpg”,“image7.jpg”,“image8.jpg”,“image9.jpg” When I got rid of the quotation marks it worked just as you said it would.

Thanks so much for your help on this. I appreciate it very much.

best regards,

Cliff

no problem:)

If you want to use XML, you can use this code

var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
	if (success) {
		var gallery = this.firstChild;
		pArray = new Array();
		for (var i = 0; i<gallery.childNodes.length; i++) {
			pArray.push(gallery.childNodes*.attributes.source);
		}
	} else {
		title_txt.text = "XML Load Error";
	}
};
gallery_xml.load("gallery.xml");

And use the attached xml-file, change it to your needs:)

scotty(-:

Hi Scotty:

Thanks for the new code and different approach. I will give it a try. Is there an advantage to this way of doing it over the other way?

Cliff

Scotty, you are truly the bomb! i have read hundreds of posts here in the past few days, and you rule. You’re always there with the answers. You’re like “Web-Gandhi”! Thanks, thanks thanks!

Ok, I know I am in trouble of becoming a pest but if I wanted to show the “title” in a textbox for each image, how would you do that. I have a hunch it’s quite simple and I have tried to make it work, but i think i have missed the boat on that. i tried doing this, thinking i was all smart now, but was quickly put in my proper place

this.pathToPics = “animation/”;
// fill this array with your pics
var gallery_xml = new XML();
timeline = this;
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
if (success) {
var gallery = this.firstChild;
pArray = new Array();
nodes = gallery.childNodes
for (var i = 0; i<gallery.childNodes.length; i++) {
pArray.push(gallery.childNodes*.attributes.source);
this.timeline[“title_txt”+i].text = nodes*.attributes.title
changePhoto(0);
}
} else {
title_txt.text = “XML Load Error”;
}

};

Can ya help me or tell me to “forget about it kid, you’ll never make it” ?

Thanks

LOL, you’re gonna make it:thumb:

var pathToPics = new String();
var pArray = new Array();
var tArray = new Array();
var fadeSpeed = 20;
var pIndex = 0;
MovieClip.prototype.changePhoto = function(d) {
	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() {
	var p = this.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;
		this.title_txt.text = this.tArray[this.pIndex];
	}
};
MovieClip.prototype.fadeIn = function() {
	if (this.photo._alpha<100-this.fadeSpeed) {
		this.photo._alpha += this.fadeSpeed;
	} else {
		this.photo._alpha = 100;
		this.onEnterFrame = null;
	}
};
var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
	if (success) {
		var gallery = this.firstChild;
		pathToPics = gallery.attributes.path;
		for (var i = 0; i<gallery.childNodes.length; i++) {
			tArray.push(gallery.childNodes*.attributes.title);
			pArray.push(gallery.childNodes*.attributes.source);
		}
		loadPhoto();
	} else {
		title_txt.text = "Error!";
	}
};
gallery_xml.load("gallery.xml");

Works with the xml.zip above;)

scotty(-:

<spam> very helpful thread!:beer: </spam>

Shoot, my spamfilter stopped working:lol:

scotty(-:

just amke an extra array and ad an attribute called textinfo or whatever

var gallery_xml = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success) {
        if (success) {
                var gallery = this.firstChild;
                pArray = new Array();
                tArray = new Array();
                for (var i = 0; i<gallery.childNodes.length; i++) {
                        pArray.push(gallery.childNodes*.attributes.source);
                        tArray.push(gallery.childNodes*.attributes.title);
                }
        } else {
                title_txt.text = "XML Load Error";
        }
};
gallery_xml.load("gallery.xml");

then add a new attribute after your source attribute in your xml.

call it title=“whatever text”

cheers

d

Wow, “It’s in the computer?..it’s so simple” Thanks loads peeps! Gonna try some crazy stuff now…so block me from your emails…there’s bound to be questions…LOL

Thanks very much everyone!

:thumb:

Hi

I’m also trying to do something similar but having some trouble, hopefully you’ll be able to help me out :slight_smile:

I basically have two movie clips at the moment: thumbnailscrollcontainer and thumbnailholder, the latter is contained in the former.

The code is all in the thumbnailscrollcontainer movie timeline.

The first frame is:


 thumbfilename = new Array();	//declare array which holds thumbnail filenames
 
 thumbfilelist = new LoadVars();
 thumbfilelist.load("photogallery.php");
 
 thumbfilelist.onLoad = function(success)
 {
 	if (success)
 	{
 		thumbfilename = thumbfilelist.thumbs.split(",");
 	}
 }
 

Then on the next frame it’s:


 
 var numfiles = thumbfilename.length; //gets length of array so we know how many times to loop
 var mcname;
 var thumbnumber;
 
 test = numfiles;
 
 for(i=0; i<=numfiles;i++)
 {
 	thumbnumber = i + 1; //Number of thumbnail being processed
 	
 	mcname = "thumbnail" + thumbnumber;
 	duplicateMovieClip("thumbnail",mcname,eval(thumbnumber));
 	mcname.loadMovie("thumbnails/" + thumbfilename*);
 	mcname._x = mcname._x + 20;
 }
 stop();
 
 

Basically I need the thumbnails dynamically loaded from a thumbnails folder.

The php script outputs:

thumbs=thumbnail1.jpg,Thumbnail2.jpg,Thumbnail3.jpg,Thumbnail4.jpg,Thumbnail5.jpg