PDA

View Full Version : Restart a cleared Interval



cortezcreations
September 5th, 2008, 10:39 PM
Hello there can anyone help me restart my setInterval after I've cleared it?

my code

function wait() {
trace("hello") ;
}

var timer = setInterval(wait,2000);

//then on a button I have

btn.onPress = function():Void {
clearInterval(timer);
}

I have this all working fine. It starts an animation and at the end of the animation I'd like to restart the interval.

Trying to figure out the function I need to create in order to restart my interval.

Thanks in advance, this one's stumping me.

Krilnon
September 5th, 2008, 10:43 PM
timer = setInterval(wait, 2000);

…or is it the end-of-animation code that is troubling you?

cortezcreations
September 6th, 2008, 08:33 AM
Thanks for the help on this!
My problem is the timer variable is on another frame the same as the wait function.
When I try to reference it in the same way I get a syntax error

var _level0.timer = setInterval(_level0.wait,2000);

//as well
timer = setInterval(_level0.wait,2000);
//just doesn't do anything for me.

hhmm at the end of the animation I have a gotoAndPlay(); command as well.
Is it possible that it's firing that too quickly and not registering my setInterval?

Cheers

cortezcreations
September 6th, 2008, 01:02 PM
Not the Interval's fault was another issue using a SoundSync class that was messing things up thanks for helping me clear it up though!