...

View Full Version : set/clear timeout



looka
08-30-2004, 08:08 PM
im using this code to clear or set timeout:
(if it is not set, function do_it is called)
but function does not work, any help?

is very unrecommanded to use multiple .js files with functions?

function play_stop () {
kri = !(ref);
if (kri) {
do_it();
change('play_d', 'stil/kv_plav.gif');
}
else {
window.clearTimeout(ref);
kricacref = false;
change('play_d', 'stil/kv_zelen.gif');
}
}

Willy Duitt
08-31-2004, 02:26 PM
What's wrong with just using: if (!ref) {
And I do not see where you are setting the setTimeout and/or if ref is global or local to the function it is defined in....

.....Willy

glenngv
09-01-2004, 07:58 AM
When you do clearTimeout(ref), the ref variable will not be reset to 0, null or something. It retains its value (which is a number) and the setTimeout delay is cleared. So doing if (!ref) will not evaluate to true on succeeding execution. The solution is to reset it 0 or null manually after clearTimeout.


function play_stop () {
if (!ref) {
do_it();
change('play_d', 'stil/kv_plav.gif');
}
else {
window.clearTimeout(ref);
ref = 0;
kricacref = false;
change('play_d', 'stil/kv_zelen.gif');
}
}

looka
09-02-2004, 10:15 AM
thanks guys, i used another function - setInterval :thumbsup:

em - one thing, if i want to have a global variable, i must set it outside the function, right?


var myglobalvar;

(some blah-blah);

function whichusesusemyglobalvar () {
};

jamescover
09-02-2004, 10:54 AM
i must set it outside the function


yes.


-james

looka
01-25-2005, 10:30 PM
no, james, it is not so.

you can set it this way(at least it works with IE and firefox 1.0):

window.myglobalvariable = 'myblah';



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum