View Full Version : Help to learn array, var?
rberry88
October 3rd, 2004, 12:12 PM
I'm not sure which method I need to be using to do what I want.
What I'm doing is setting up a photo gallery, I have all my thumbnails saved to a folder with names of thumb01.jpg to thumb21.jpg and all my large photos (what the user sees after they click on the thumbnail) in a separate folder and named large01.jpg to large21.jpg.
I've been reading about arrays, vars, lists ect and I'm not sure which is the best (easiest to understand, and change later) way to accomplish loading the thumbnails on the stage and then the large photo once the thumbnail is clicked.
If someone can advise which method would be the best and someplace I can get information about putting the code together I would appreciate it.
tizzle
October 3rd, 2004, 04:36 PM
If you store your data seperately from your flash file, say in an XML or comma seperated text file you don't even have to open flash to change the values. you simply add a another line to your XML or text file anytime you have a new picture to put up. Get a heads up here:
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm
rberry88
October 4th, 2004, 08:31 AM
Yeah, I saw and read through that tutorial but I don't fully understand how to use XML (or php for that matter) so instead of just copying and pasting something and not knowing what it did, I figured I would stick to using AS.
I've come up with the following, with help from someone else, and I understand what the code is trying to accomplish but there is a syntax error (where the > are) that I can't solve:
var thumbs = new Array();
var large = new Array();
for (i=1; i<22; i++) {
_root.createEmptyMovieClip("thumb_holder" + i, i);
> ****thumb_pic = "thumb" + i + ".jpg";
>****large_pic = "large"+i+".jpg";
****_root["thumb_holder"+i]._y = 200;
****_root["thumb_holder"+i]._x = i*50;
>****_root["thumb_holder"+i].loadMovie("thumbs/", thumb_pic);
****thumbs.push("thumbs/", thumb_pic);
****large.push("large/", large_pic);
}
My pictures that I want to use are each in separate folders where my .swf is.
My .swf is in Home/ and my pictures are at Home/thumbs/ and Home/large/, if that makes sense.
Any help is appreciated.
tizzle
October 4th, 2004, 08:44 AM
loadMovie, in this case, only needs one var namely the name of the image. So you should have something like:
_root.createEmptyMovieClip("thumb_holder" + i, i);
var thumb_pic = "thumb" + i + ".jpg";
var large_pic = "large" + i + ".jpg";
_root["thumb_holder"+i]._y = 200;
_root["thumb_holder"+i]._x = i*50;
_root["thumb_holder"+i].loadMovie("thumbs/" + thumb_pic);
note that the , (comma) was replaced with a + (plus sign) to concatenate the path and the filename.
I'm not sure why you would need the arrays here since you don't actually use them in this code. If you need to do somthing with the arrays after you have loaded all the images you can add them again as you did but change the comma for a plus sign here too.
thumbs.push("thumbs/" + thumb_pic);
large.push("large/" + large_pic);
good luck.
rberry88
October 4th, 2004, 09:20 AM
That code works (no syntax errors) but when I test the movie it gives me the error of "thumbundefined":
thumbundefined.jpg
largeundefined.jpg
It keeps repeating this for what looks like all 21 times, once for each picture.
I'm wondering if I should name my pics something besides thumb1.jpg...thumb21.jpg, or does that even matter?
tizzle
October 4th, 2004, 12:01 PM
it prints undefined for variables it cannot find try putting var in the for loop where you first initiate the i variable:
for (var i=1; i<22; i++) {
_root.createEmptyMovieClip("thumb_holder" + i, i);
var thumb_pic = "thumb" + i + ".jpg";
var large_pic = "large" + i + ".jpg";
_root["thumb_holder"+i]._y = 200;
_root["thumb_holder"+i]._x = i*50;
_root["thumb_holder"+i].loadMovie("thumbs/" + thumb_pic);
}
it may still not find your images but then the error should be:
Error opening URL "thumbs/thumb14.jpg"
notice undefined is an actual number now
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.