# For loop, jpg load

**URL:** <https://forum.kirupa.com/t/for-loop-jpg-load/21131>\
**Category:** flash\
**Created:** [May 17, 2003, 6:45pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131 "2003-05-17T18:45:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RvGaTe](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rvgate/32/126_2.png) [@RvGaTe](https://forum.kirupa.com/u/RvGaTe)\
**Post date:** [May 17, 2003, 6:45pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/1 "2003-05-17T18:45:33Z")

</div>

allright, this is the problem

i’m buzy with my portfolio, and i made this script for loading dynamic jpg’s into an flash movie, with only assigning an number of pictures…

here’s the lil script

```auto

for (i=1; i<=5; i++) {
	_root.createEmptyMovieClip("pic_"+i, i);
	with (_root["pic_"+i]) {
		file = "images/portfolio_"+i+".jpg";
		loadMovie(file);
		_x = 55*i
		trace(i+"="+file+" _____X="+_x+"_____ Y="+_y+" _____L="+i+"_____ I="+_name);
	}
}

```

it create’s an empty mc (pic\_1 to pic\_5) and load the assigned jpg into it (images/portfolio\_1 to \_5), and assigning the possitions next to each other (pictures are 50x50) with 5 space between them…

script looks alright, and the trace output is as i xpected, but it dozn’t seem to work correctly, it gives no errors at all, and i can only c picture 1… no more, no less, and \_x of the mc isn’t as it should be…

what am i doing wrong ?

ps: Flash [MX]

---

<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:** [May 17, 2003, 7:32pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/2 "2003-05-17T19:32:42Z")

</div>

Try this. photoArray\*.pic has the paths to each pic. This code works for me.

```auto

	createEmptyMovieClip("mc", -100);
	for(i=0;i<10;i++)
	{
		tn = "tn" + i;
		duplicateMovieClip(mc, tn, i);
		this[tn].loadMovie(photoArray*.pic);
		photoArray*.pic._x = i*50; 
				
	}

```

hope it helped ya

---

<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:** [May 17, 2003, 7:38pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/3 "2003-05-17T19:38:10Z")

</div>

Excellent nickname, boris! 😛 I love that movie.

---

<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:** [May 17, 2003, 8:02pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/4 "2003-05-17T20:02:00Z")

</div>

hmmm, i cant get it to work with your code boris… dont know why…

what do you mean with, photoArray\*\*\*.pic\*\* ???

plz xplain how your code works, or post an .fla to be more clear

edit: ilyaslamasse… please… dont

---

<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:** [May 18, 2003, 6:30pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/5 "2003-05-18T18:30:37Z")

</div>

Thanks ilyaslamasse, that movie is too cool. Whats weird is my neighbor looks just like that Boris the Blade.

Onto buisness…

Aight, I changed the code to be alittle more generic I guess and added explications. Forget about the .pic thing, I was using an Array filled with a customized object.

```auto

numpics = 20;
photoArray = new Array(numpics);

//Now, load the array with the path of the jpgs
//the jpgs should be named: p0.jpg, p1.jpg . . . p(n-1).jpg, pn.jpg
//but of course you can change this to suit your needs

for (i = 0; i<numpics;i++)
     photoArray* = ("p" + i + ".jpg");

//now we create an empty movie clip to load the jpgs into
createEmptyMovieClip("mc", -100);

//this for loop duplicates the "mc" clip 
//we just made, and loadMovie() the jpg into
// that clip, then we position the clip with
// the last line.
for(i=0;i<numpics;i++)
{
        tn = "tn" + i;
        duplicateMovieClip(mc, tn, i);
        this[tn].loadMovie(photoArray*);
        this[tn]._x = i*50;
        
}

```

Now I hoped this help clear things up for you. If not then I’ll attach a .fla for you.

---

<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:** [May 18, 2003, 7:14pm UTC](https://forum.kirupa.com/t/for-loop-jpg-load/21131/6 "2003-05-18T19:14:15Z")

</div>

allright, thx for the xplenation, but, as i look tru the code, it is excactly the same as mine, only the file path is stored in an array…

so it dozn’t make any differents, so i thought, this cant be a code problem, and it isn’t, i figured out that my .jpg’s were to progressive.

the real problem here lays in the jpg it self… i made the jpg’s in photoshop and DIDN’T save them for web, but as a normal .jpg… thats why they are to progressive.

so, without editing my own code, i re-saved all the jpg’s being used, and saved them for web…

now it all works fine… (thx for checking this up david)

thanks for the reply’s tho :S
