Groups | Blog | Home
all groups > flash actionscript > december 2004 >

flash actionscript : Loading images?


xcx
12/11/2004 9:03:49 PM
I try to make image gallery but I don't want to import all images to fla file.
I try to make script what loads my images from folder. I have write this
script but it won't work.

var img_count = 6;

// Loading images.
for (var ind=0; ind < img_count; ind++)
{
images[ind] = "img"+ind;
_root.createEmptyMovieClip(""+images[ind], this.getNextHighestDepth());
images[ind].loadMovie(""+images[ind]+".jpg");
}

Last line is my problem or I think it is. Flash debugger give me no errors,
but nothing happens when I run script. If I change last line like this.

img0.loadMovie(""+images[ind]+".jpg");

One image will be loaded so flash don't like my idea to use array values as
movieclip name. Can I even use variable value as movieclip name? If I can't
use array values as movieclip name how I can load many jpg files whit script
and change image parameters after loading.
NSurveyor
12/11/2004 9:31:55 PM
It's good to declare your array. At the beginning, add:
images = new Array();

Also, change the last line to:
_root[images[ind]].loadMovie(""+images[ind]+".jpg");

The problems is, images[ind] are strings. And you can't do "img0".loadMovie.
It doesn't make sense. So, using array syntax, you can do _root["img0"] to find
_root.img0.
kglad
12/11/2004 9:34:33 PM
for(ind=-;ind<img_count;ind++){
rclip=_root.createEmptyMovieClip("imgHolder"+ind,this.getNextHighestDepth());
rclip.loadMovie("img"+ind+".jpg");
NSurveyor
12/11/2004 9:37:13 PM
kglad, you didn't open flash to type this did you?
xcx
12/11/2004 9:42:19 PM
Thank for your help. Array was allready declared, but I missed it when I copy this script. Anyway. I got work whit that _root[images[ind]].loadMovie(""+images[ind]+".jpg"); line. Thanks again! :)
NSurveyor
12/11/2004 9:50:24 PM
You're welcome. But you know, kglad's script is a lot shorter and simpler, only
4 lines!

var img_count = 6
for(ind=0;ind<img_count;ind++){
rclip=_root.createEmptyMovieClip("imgHolder"+ind,this.getNextHighestDepth());
rclip.loadMovie("img"+ind+".jpg");
}
xcx
12/11/2004 11:10:02 PM
Kglad's script may be simpler but that script seems to load every images to
rclip and not that empty movieclip. Why? If kglad not load image to emptymovie
why he even makes it? Well I think than that is just littele bug :) but yes it
is littele simpler.
NSurveyor
12/11/2004 11:32:26 PM
Kglad's just using a technique -- someVar = createEmptyMovieClip(...); and then
you can do whatever to the created movieclip with someVar.loadMovie(...) or
whatever. It saves some time, instead of writing _root['imgHolder'+ind] you can
just write rclip.
NSurveyor
12/11/2004 11:36:18 PM
[quoted text, click to view]
Rothrock
12/12/2004 12:59:52 AM
Yes this is one of the coolest (and most useful) tricks I have learned. The
createEmptyMovieClip method returns a reference to the movie you create, in
this case each time through the loop rclip will be imgHolder0, imgHolder1, etc.
You can then use that variable instead of the name of the movieclip. This can
be really useful especially if you want to manipulate the properties of the
clip etc. Add a trace('The current clip is '+rclip); after the loadMovie and
observe the trace window in the testing environment. (Oh and PS, kglad is like
Master Po. Aside from the occasional typo :) if he does something there is
usual a good reason for it. And if you don't understand, you should try or ask,
because it is probably something you wish somebody would have told you long
ago! Really!)
kglad
12/12/2004 7:02:36 AM
yep, i goofed again. i hit the minus key (one key to the right of that
intended zero key).

and yes, i use rclip in to minimize typing (and the chances of typos) and in
recognition of byron canfield (http://www.byronc.com/nf_about.shtml) who was a
frequent contributer here and from whom i learned much including the use of
rclip to represent a recently created (or attached) movieclip.
xcx
12/12/2004 9:54:15 AM
xcx
12/12/2004 10:04:54 AM
Sorry kglad ( Master Yoda :) )

AddThis Social Bookmark Button