[AS]//varial to hold how many movies are you loading
var totalClips = 30;
function selectMovie() {
//variable to get random numer
//loads random number between 1 (+1 at the end) and 30 (total clips)
var randomNumber = random(totalClips)+1;
//load random movie
//this assumes your movies names are file1, file2, file3, etc
clipToLoadTo.loadMovie(“file”+randomNumber+".swf");
}
//create setInterval
var loadInterval = setInterval(selectMovie, 60000);[/AS]
I commented the code, so if you have any questions feel free to ask, but right now I am going to go over setInterval.
We first define setInterval as a variable. It will still run the setInterval code, but it allows us to target our setInterval later if we ever need to use clearInterval (will explain in a bit).
setInterval works like this…
[AS]setInterval(function, time);[/AS]
The function in this case is called selectMovie. And the time is set to 60000 because setInterval times itself in milliseconds. So 1000 = 1 second. And 60 seconds = 1 minute so 60*1000 = 60000 right? This will then call the function every 60 seconds.
If you ever want to clear your interval to get it to stop running you can use this… [AS]clearInterval(intervalName);[/AS] In our case intervalName would be loadInterval.
Ok, now that I got setInterval explained, lets go over the function.
The function first declare a variable to store a random number from 1 to 30. It then calls a loadMovie script. You know how loadMovie works right? (I assume). Well as you see in our script the movie we load is called “file”+randomNumber. This will take the random number produced in the randomNumber variable and attached it to the end of the word “file” creating it to be like file1, file2, file3, file4, etc, etc. Then of course the “.swf” attaches that to the end so it becomes file1.swf, file2.swf, file3.swf, etc, etc.
I hope that helps.