# Loading images problem

**URL:** https://forum.kirupa.com/t/loading-images-problem/58093
**Category:** Uncategorized
**Created:** [July 19, 2004, 7:03pm UTC](https://forum.kirupa.com/t/loading-images-problem/58093 "2004-07-19T19:03:12Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![afmaury](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@afmaury](https://forum.kirupa.com/u/afmaury)
#### Post date: [July 19, 2004, 7:03pm UTC](https://forum.kirupa.com/t/loading-images-problem/58093/1 "2004-07-19T19:03:12Z")

</div>

I have an array of 49 images (.jpg). I need to write a function that will load them each into their own mc. I want to just write code to create the 49 empty clips, rather than having to create them all.

I have been trying to use a for loop. The loop would go through 49 times and create a clip each time and then load it with the next image in the array. I also want to be able to give each clip a unique x and y position, which I hope to do by using the loops counter and multiplying by a value. My code is not working at all. I was hoping that someone could help with a code for this.

Thanks 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: [July 19, 2004, 7:40pm UTC](https://forum.kirupa.com/t/loading-images-problem/58093/2 "2004-07-19T19:40:18Z")

</div>

How far did you come? (post a fla/code)

scotty(-:

---

<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: [July 19, 2004, 11:06pm UTC](https://forum.kirupa.com/t/loading-images-problem/58093/3 "2004-07-19T23:06:42Z")

</div>

Here is what I have right now. I know there is a lot wrong with it and I have tried changing a lot of things. Thanks for helping out!

> pathToPics = “bridgeParts/”;

Array.prototype.loadImages=function(){  
for(j=0;j\<this.length;j++){  
this.createEmptyMovieClip (“emptyClip”+j, j);  
loadMovie(pathToPics.arr1[j], “movieclip” +j);  
“movieclip”+j.\_x = j\*230

```
}

```

---

<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: [July 20, 2004, 6:57am UTC](https://forum.kirupa.com/t/loading-images-problem/58093/4 "2004-07-20T06:57:31Z")

</div>

Fill the pArray with your pictures;)

```auto
var pathToPics = "bridgeParts/";
pArray = new Array();
pArray = ["image0.jpg", "image1.jpg", "image6.jpg", "image7.jpg", "image8.jpg", "image9.jpg"];
function loadImages() {
	for (j=0; j<pArray.length; j++) {
		new_mc = this.createEmptyMovieClip("emptyClip"+j, j);
		new_mc.loadMovie(pathToPics+pArray[j]);
		//if you want 49 pictures I've doubts about the next line
		//the last picture will have a _x=11040 ????
		new_mc._x = j*230;
	}
}
loadImages();

```

scotty(-:

---

<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: [July 22, 2004, 3:52am UTC](https://forum.kirupa.com/t/loading-images-problem/58093/5 "2004-07-22T03:52:57Z")

</div>

Thanks Scotty! I got it working perfectly. I knew I wouldn’t be able to do that 230\*49 thing, but I also knew I could change that stuff. I ended up having a bunch of “if” statements and put the pics on 7 different rows. Thanks a lot for your help.

---

<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: [July 22, 2004, 4:18am UTC](https://forum.kirupa.com/t/loading-images-problem/58093/6 "2004-07-22T04:18:32Z")

</div>

instead of if statements use something like this:  
[AS]  
\_root.numOfItemsPerRow = 10;  
\_root.xSpacing = 10;  
\_root.ySpacing = 10;  
\_root.numOfPics = 49;  
for (i=0; i\<\_root.numOfPics; i++) {  
new\_mc = this.createEmptyMovieClip (“emptyClip”+i, i);  
new\_mc.loadMovie(pathToPics.arr1\*);  
row = Math.floor(i/\_root.numOfItemsPerRow);  
new\_mc.\_x = 30+(\_root.xSpacing_i)-((\_root.xSpacing_\_root.numOfItemsPerRow)_row);  
new\_mc.\_y = 30+(\_root.ySpacing_row);  
}  
[/AS]

---

<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: [July 22, 2004, 5:38am UTC](https://forum.kirupa.com/t/loading-images-problem/58093/7 "2004-07-22T05:38:43Z")

</div>

no problem, afmaury:thumb:  
=)paradox244=)

---

<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: [July 22, 2004, 6:38am UTC](https://forum.kirupa.com/t/loading-images-problem/58093/8 "2004-07-22T06:38:54Z")

</div>

good call, paradox! i like that code. i figured there was a better way than to write about 6 “if” statements. i will definitely keep that in mind in the future.
