Randon images

Hi everyone,

I want that in every 5 sec a randon image loads in my site. How do I do that?

Fernando, from Brazil

img = ["pic1.jpg", "pic2.jpg", "pic3.jpg"];
loadimg = function () {
	r = Math.floor(Math.random()*img.length);
	emptyMovieClipInstanceName.loadMovie(img[r])
}
loadimgi = setInterval(loadimg, 5000);

don’t forget to replace emptyMovieClipInstanceName with the actual instance name of the movie clip where you want to load the images :slight_smile:

and i’ve seen a few questions about this … you might want to try a search as well :wink:

hi kax… wellcome to kirupa zone :wink:

function randomLoading() {
	_root.createEmptyMovieClip("holder", 1);
	holder._x = 50;
	holder._y = 50;
	myArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"];
	picker = Math.floor(Math.random()*(5));
	_root.holder.loadMovie(myArray[picker]);
};
setInterval(randomLoading, 5000);{

put your jpg files in the same folder with your SWF… give it the name like 2.jpg… etc

i hope it helps… :wink:

hi kax… wellcome to kirupa zone :wink:

what ?? :stuck_out_tongue:

function randomLoading() {
	_root.createEmptyMovieClip("holder", 1);
	holder._x = 50;
	holder._y = 50;
	myArray = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg"];
	picker = Math.floor(Math.random()*(5));
	_root.holder.loadMovie(myArray[picker]);
};
setInterval(randomLoading, 5000);{

first … i’d change this line

picker = Math.floor(Math.random()*(5));

to

picker = Math.floor(Math.random()*myArray.length);

second … that’s basically the same code i posted :wink:

hi kax… wellcome to kirupa zone
what??

i mean hi fspaiva… :sigh:
while i post my replay you did in the same time so i didn’t see your replay…

hmm … 14 mins difference … i wouldn’t say that we posted at the same time :stuck_out_tongue: