JavaScript Function Return

R

RC-

I have been trying to figure out how to stop a function from running after 3
seconds have passed; I can not, for the live of me, figure out how to get
the funtion to stop running!

Here is the function:

/* Rotate selected objects */
function rotateObjects() {
for (var i = 0; i < pos.length; i++) {
pos += inc; objects.visibility = 'visible';
objects.left = (r * Math.cos(pos)) + xoff
objects.top = (r * Math.sin(pos)) + yoff;
}
rotateTimer = setTimeout("rotateObjects()", 75);

}

I've tried everyting I can think of to get the function to stop; I've tried
Break, Return, setInterval, setTimeout, blah, blah, blah.

Any help will be great!

TIA
RC-
 
J

Jon Spivey

The function will keep calling itself. If you want it to just run once move
the settimout outside the function.

function rotateObjects(){
// stuff
}
rotateTimer = setTimeout("rotateObjects()", 75);

Cheers,
Jon
Microsoft MVP
 
R

RC-

Jon, thanks for the reply.

When I move the code outside of the funtion, the objects no longer rotate, I
get one little nudge but that's it. I would like the items to rotate for
about 3 seconds then stop then run another function. Any ideas how I can get
it to run for 3 seconds? I tried a FOR statement, but I am unsure how the
FOR statement works in Java (I'm a VB guy)

Jon Spivey said:
The function will keep calling itself. If you want it to just run once
move the settimout outside the function.

function rotateObjects(){
// stuff
}
rotateTimer = setTimeout("rotateObjects()", 75);

Cheers,
Jon
Microsoft MVP

RC- said:
I have been trying to figure out how to stop a function from running after
3 seconds have passed; I can not, for the live of me, figure out how to
get the funtion to stop running!

Here is the function:

/* Rotate selected objects */
function rotateObjects() {
for (var i = 0; i < pos.length; i++) {
pos += inc; objects.visibility = 'visible';
objects.left = (r * Math.cos(pos)) + xoff
objects.top = (r * Math.sin(pos)) + yoff;
}
rotateTimer = setTimeout("rotateObjects()", 75);

}

I've tried everyting I can think of to get the function to stop; I've
tried Break, Return, setInterval, setTimeout, blah, blah, blah.

Any help will be great!

TIA
RC-

 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top