PDA

View Full Version : For loop, jpg load



RvGaTe
May 17th, 2003, 02:45 PM
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



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]

boristheblade
May 17th, 2003, 03:32 PM
Try this. photoArray[i].pic has the paths to each pic. This code works for me.


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

}



hope it helped ya

pom
May 17th, 2003, 03:38 PM
Excellent nickname, boris! :P I love that movie.

RvGaTe
May 17th, 2003, 04:02 PM
hmmm, i cant get it to work with your code boris... dont know why.....

what do you mean with, photoArray[i].pic ???

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



edit: ilyaslamasse.... please...... dont

boristheblade
May 18th, 2003, 02:30 PM
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.



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[i] = ("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[i]);
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.

RvGaTe
May 18th, 2003, 03:14 PM
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