PDA

View Full Version : loading dynamic thumbs/pics (attn: Scotty)



dru_nasty
July 14th, 2004, 09:55 PM
How would I get the first "pic" to show automatically? Since when the code runs, it only shows the thumbs first, until you click on one and then it loads the corresponding pic.




/*The below works if the pictures and thumbs are in a folder "pics"
the thumbs are named "thumb1.jpg" etc and the pictures "pic1.jpg" etc
if you use other names, change it in the code as well;-))

scotty(-:

*/
var k = 0;
//nr is amount of thumbs
var nr = 2;
//gap is the gap between the thumbs
var gap = 10;
//c is the amount of columns
var c = 3;
//set the original thumb invisible
thumb._visible = 0;
//function to create the thumbs
function createThumbs() {
for (var i = 0; i<nr; i++) {
//duplicate the original thumb
duplicateMovieClip("thumb", "pic"+i, i);
//give the copy a (more easy) name
p = this["pic"+i];
//give the copy it's own identifier
p.i = i;
//set the x position of each thumb
p._x = 300+((i%c)*(p._width+gap));
//set the y position of each thumb
p._y = 350+((Math.floor(i/c))*(p._height+gap));
//set the actions for the thumb you can add rollover etc
p.onRelease = function() {
//load the pic in container , here you need the identifier;-))
container.loadMovie("pics/pic"+(this.i+1)+".jpg");
};
}
//call the loadthumb function
loadThumb(0);
}
function loadThumb(k) {
//give the "container" inside the thumb a name
mc = this["pic"+k].th_pic;
//load the thumb
mc.loadMovie("pics/thumb"+(k+1)+".jpg");
//set the thumb picture invisible
mc._visible = 0;
//create an emptymovieclip
ab = this.createEmptyMovieClip("temp", 100);
ab.onEnterFrame = function() {
//if the thumb picture is fully loaded
if (mc.getBytesLoaded() == mc.getBytesTotal() && mc.getBytesTotal() != 0) {
//set the thumb picture visible
mc._visible = 1;
delete this.onEnterFrame;
//if not all thumb pictures are loaded
if (k<nr) {
//call the nextthumb function
//I've used a setinterval here cause the thumbs are very small
//so the effect of consecutive loading is small as well
//change the 300 to the value you like (300 is in msecs)
delay = setInterval(nextThumb, 300);
}
}
};
}
function nextThumb() {
//increase the value k
k++;
//call the function loadthumb
loadThumb(k);
//clear the interval
clearInterval(delay);
}
//call function createthumbs (to start it all;-))
createThumbs();


Also, what would I have to change in order to load swf's as opposed to just the "pics"? I know it would involve changing this line of code....


container.loadMovie("pics/pic"+(this.i+1)+".jpg");

:beer:

scotty
July 15th, 2004, 03:07 PM
For the swf's:

container.loadMovie("pics/pic"+(this.i+1)+".swf");
if they're in a folder pics;)

For loading the first pic:
grr can't copy the part I need, moment:lol:

scotty(-:

scotty
July 15th, 2004, 03:12 PM
Back again=)
Look for the if(k<nr){ part in the code and add the else statement

if (k<nr) {
delay = setInterval(nextThumb, 300);
} else {
container.loadMovie("pics/pic1.jpg");
}
Not tested, but a good chance it'll work:)

scotty(-:

dru_nasty
July 15th, 2004, 03:26 PM
Thanks Scotty, Im gonna try this as soon as I'm done at work.

dru_nasty
July 15th, 2004, 05:25 PM
Brilliant! (as always) :beer:
thanks again Scotty!

scotty
July 15th, 2004, 05:42 PM
:lol:welcome:thumb: