# Dynamically loading Images

**URL:** <https://forum.kirupa.com/t/dynamically-loading-images/12475>\
**Category:** flash\
**Created:** [January 31, 2003, 6:26pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475 "2003-01-31T18:26:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kel\_420](https://avatars.discourse-cdn.com/v4/letter/k/5e9695/32.png) [@Kel\_420](https://forum.kirupa.com/u/Kel_420)\
**Post date:** [January 31, 2003, 6:26pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/1 "2003-01-31T18:26:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 31, 2003, 6:40pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/2 "2003-01-31T18:40:59Z")

</div>

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

```php
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)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 31, 2003, 7:04pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/3 "2003-01-31T19:04:15Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 31, 2003, 7:06pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/4 "2003-01-31T19:06:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 31, 2003, 7:09pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/5 "2003-01-31T19:09:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [January 31, 2003, 7:11pm UTC](https://forum.kirupa.com/t/dynamically-loading-images/12475/6 "2003-01-31T19:11:17Z")

</div>

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.
