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.
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.
for(ind=-;ind<img_count;ind++){ rclip=_root.createEmptyMovieClip("imgHolder"+ind,this.getNextHighestDepth()); rclip.loadMovie("img"+ind+".jpg");
kglad, you didn't open flash to type this did you?
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! :)
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"); }
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.
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.
[quoted text, click to view] >>you can just write rclip.
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!)
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.
Sorry kglad ( Master Yoda :) )
Don't see what you're looking for? Try a search.
|