PDA

View Full Version : setTimeout & mouseMove



adrock
February 16th, 2008, 12:37 PM
I made a quick scrolling banner for a friend. There are buttons scrolling by in a loop and I was just trying to make the loop stop when the mouse rolled over a button to read, or push it.

I tried setInterval first, and now setTimeout. My problem is, the length of time is not consistent. When the .swf first starts, it takes a 5 second break, and starts scrolling again. After stopping it again and again with a mouse movement, it eventually becomes a much shorter pause than 5 seconds.

Any ideas?


onClipEvent (mouseMove) {
stop();
setTimeout(please, 5500);
function please(){
play();
updateAfterEvent;
}
}

AuroraMedia
February 16th, 2008, 03:48 PM
Are you talking action script or java script here? It must be javascript as setTimeout is not an action script function.

Anyways, the reason why the time is shortening is because you are not clearing the timeout and thus creating multiple instance of the timeout function.

Lets say an instance is initiated, and before the end of those 5 secs the mouse moves again, another instance is then being created without destroying the first instance which is due for trigger in less than 5 secs now.

Hope it is clear.

Your script should go something like this.

onClipEvent (mouseMove) {
clearTimeout(trig);
stop();
trig = setTimeout(please, 5500);
function please(){
play();
updateAfterEvent;
}
}

AuroraMedia
February 16th, 2008, 03:52 PM
Hi again,

Sorry, did not realize you were talking about Flash CS3 and not AS 2.0, hence the comment about action scirpt and java script does not hold. But the explanation to your problem and the solution is still very true.



I made a quick scrolling banner for a friend. There are buttons scrolling by in a loop and I was just trying to make the loop stop when the mouse rolled over a button to read, or push it.

I tried setInterval first, and now setTimeout. My problem is, the length of time is not consistent. When the .swf first starts, it takes a 5 second break, and starts scrolling again. After stopping it again and again with a mouse movement, it eventually becomes a much shorter pause than 5 seconds.

Any ideas?


onClipEvent (mouseMove) {
stop();
setTimeout(please, 5500);
function please(){
play();
updateAfterEvent;
}
}

adrock
February 20th, 2008, 04:11 PM
I knew there was probably something that needed to be cleared out. I search and did loads of tutorials trying to find something similar to what I wanted to do, when I realized that it if I cleared my head and and started from scratch it was probably so simple that a tutorial wasn't needed for most folks.

So, I dusted off my old Flash book and started reading about different functions and started from scratch. However, like many books, it gave me such a simplified example of using setTimeout and SetInterval that it didn't explain clearing it out.

Thanks again.

glosrfc
February 20th, 2008, 04:23 PM
Just one correction...setTimeout() is an available function in AS 2.0, it's just not documented.