Dynamically loading Images

I want to be able to load images dynamically. Like I call them 01.jpg, 02.jpg and so on…
Now, if I only have say 5 images, when it gets to the fifth and you click next it takes you back to the first one again BUT if I add more images [06.jpg, 07.jpg…] it finds them without me having to update the script.

I know this must be a pretty easy one, but I’m all alone in the office and I can’t figure it out.

Would it be possible to customize this code to do what I want or is it a job for PHP??

_root.createEmptyMovieClip(“imageloader”,1);
container.loadMovie(“photo.jpg”);
container._x = container._y = 50 ;

Any help will be greatly appreciated.

Thanx in advance

Ok, this is untested, but try something like this…

i = 0;
imageArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"];
_root.createEmptyMovieClip("container", 1);
container._x = container._y=50;
_root.onEnterFrame = function() {
	if (Key.isDown(Key.RIGHT)) {
		container.loadMovie(_root.imageArray[i++]);
		if (i>=_root.imageArray.length) {
			i = 0;
		}
	}
	if (Key.isDown(Key.LEFT)) {
		container.loadMovie(_root.imageArray[--i]);
		if (i<=0) {
			i = 5;
		}
	}
};

(note: I used key pressed for left and right to change images)

Thanx man. I will test it tonight as I am drowning in work right now.

It looks like you still have to add the 01.jpg, 02.jpg… to the script though. I was hoping that I wouldn’t have to update the code at all.

I want to be able to just upload images to the folder. When it gets to the last image, it loads the first one again. If I add more images I want it to know automatically. I realize that I can’t call the .JPG anything, that’s why I used the 01.jpg, 02.jpg and not things like dog.jpg, sun.jpg

Thanx again for taking the time to answer, and I will give it a try. :nerd:

Well as far as I know there is no way for Flash to detect all the images in a given directory, you will have to add the extra images to the script no matter what.

Thanx again man.
I could have sworn it was possible… Ahh well, back to the drawing board.

You might be able to load the array with something like loadVars or something.

Then your array of images could be in a .txt file or something.

I don’t work with that, so I am not sure if that is possible.