all groups > flash actionscript > august 2006 >
You're in the

flash actionscript

group:

setInterval and clearInterval problems


setInterval and clearInterval problems gregmax17
8/20/2006 9:29:52 PM
flash actionscript:
Really simple question, take a look at the script I am using:

_root.end = setInterval(function() {
clearInterval(_root.end);
gotoAndStop(20);
trace('end----------');
}, 1500);

Why does it keep tracing 'end---------'? Any help would be appreciated. Thanks
in advance.
Re: setInterval and clearInterval problems kglad
8/20/2006 9:44:37 PM
Re: setInterval and clearInterval problems abeall
8/20/2006 9:46:14 PM
Works for me. But if it keeps tracing 'end--------' then it sounds like the
interval is not being cleared for some reason. Or perhaps you are setting the
interval in an onEnterFrame so it keeps being reset.
Re: setInterval and clearInterval problems abeall
8/20/2006 9:48:12 PM
FYI, if you are publishing to Flash 8, you can just use setTimeout for these sort of uses:
http://www.flashguru.co.uk/flash-8-settimeout/
Re: setInterval and clearInterval problems gregmax17
8/20/2006 10:05:51 PM
Re: setInterval and clearInterval problems kglad
8/20/2006 10:06:54 PM
Re: setInterval and clearInterval problems gregmax17
8/20/2006 10:30:13 PM
No, it is not in a frame loop. Here is an example of the structure of the AS in
the frame:

function update() {
trace('update---------');
clearInterval(_root.pause_update);

if(this_occurs) {
//do this
ready_lvl_up = setInterval(lvl_up, 1500, "para_1");
} else if(that_occures) {
//do that
ready_lvl_up = setInterval(lvl_up, 1500, "para_2");
} else {
_root.end = setInterval(function() {
clearInterval(_root.end);
gotoAndStop(20);
trace('end----------');
}, 1500);
}
}

function lvl_up(category) {
clearInterval(ready_lvl_up);

if(category == "this") {
//do this
} else if(caetgory == "that") {
//do that
}
}

_root.pause_update = setInterval(update, 1500);

stop();

Now tell me, do you see any frame loop?
Re: setInterval and clearInterval problems abeall
8/20/2006 10:55:19 PM
To see a frame loop you'd have to inspect the FLA, since it's frame level, not
script level. However, you have a stop() in that script, so unless it's being
set to play() or gotoAndPlay() from some other code then there isn't likely a
frame loop.

But I can tell you that copy/pasting that code into a new doc and publishing
in SWF6 and AS1 or AS2 works, so it must be something somewhere else that is
causing the problem.
Re: setInterval and clearInterval problems kglad
8/20/2006 11:41:45 PM
Re: setInterval and clearInterval problems gregmax17
8/20/2006 11:42:20 PM
Re: setInterval and clearInterval problems kglad
8/21/2006 12:37:49 AM
AddThis Social Bookmark Button