PDA

View Full Version : Having Problems with SetInterval



norrillous
January 8th, 2004, 06:12 PM
I am trying to make a banner like item for a website I am working on, I have 1 external text file 4 external swf's and 1 external .jpg
that I am trying to get to do this:

on page load display img1.jpg for 60 seconds and then randomly select a number and then display the file that is associated with that number, for 60 seconds, and do it again, and again until all of the text and swf files have been displayed and then start over from the beginning,
Now I can get it to select a random number and then pull up a file that is associated with that number with this code

I have shortened the time to see it work but still no avail

Example random code:


Movienum = Math.floor(math.random()*5);
if(Movienum == 0) loadVariableNum ("loaded_Text.txt", 0)
if(Movienum == 1) loadVariableNum ("1.swf", 0)
if(Movienum == 2) loadVariableNum ("2.swf", 0)
if(Movienum == 3) loadVariableNum ("3.swf", 0)
if(Movienum == 4) loadVariableNum ("4.swf", 0)

Now with the SetInterval I tried this and wound up with squat
can somebody PLEASE help me I am starting to get Desperate

New Example code:


Movienum = Math.floor(math.random()*5);
function countDown() {
if (Movienum == 0) {
loadVariablesNum("loaded_text.txt", 0);
} else {
loadVariablesNum("img1.jpg", 0);
clearInterval(timer);
}
}
timer = setInterval(countDown, 1000);
function countDown() {
if (Movienum == 1) {
loadVariablesNum("1.swf", 0);
} else {
loadVariablesNum("img1.jpg", 0);
clearInterval(timer);
}
}
timer = setInterval(countDown, 1000);
function countDown() {
if (Movienum == 2) {
loadVariablesNum("2.swf", 0);
} else {
loadVariablesNum("img1.jpg", 0);
clearInterval(timer);
}
}
timer = setInterval(countDown, 1000);
function countDown() {
if (Movienum == 3) {
loadVariablesNum("3.swf", 0);
} else {
loadVariablesNum("img1.jpg", 0);
clearInterval(timer);
}
}
timer = setInterval(countDown, 1000);
function countDown() {
if (Movienum == 4) {
loadVariablesNum("4.swf", 0);
} else {
loadVariablesNum("img1.jpg", 0);
clearInterval(timer);
}
}
timer = setInterval(countDown, 1000);

norie
January 9th, 2004, 06:16 AM
please don't cross post.
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=43751
what was wrong with my code?

Howard
January 9th, 2004, 07:26 AM
Hi,

Does

Movienum = Math.floor(math.random()*5);
if(Movienum == 0) loadVariableNum ("loaded_Text.txt", 0)
if(Movienum == 1) loadVariableNum ("1.swf", 0)
if(Movienum == 2) loadVariableNum ("2.swf", 0)
if(Movienum == 3) loadVariableNum ("3.swf", 0)
if(Movienum == 4) loadVariableNum ("4.swf", 0)

work okay?

You appear to have several identically named functions. There should be one function with the decision making logic within.

norrillous
January 9th, 2004, 03:19 PM
Yea it works but u have to refresh everytime u want a different movie displayed and that is not what I need it to do