How do i stop a function?

Hi

Im running a CountDown Timer function and was wondering if there is a way to remove or stop it’s “function’s” when the user presses a button.

Theres actually a few functions, one example:

ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#000000]function[/COLOR] CountDownTimerCOLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]</p>
<p> AsBroadcaster.[COLOR=#000080]initialize[/COLOR]COLOR=#000000[/COLOR];</p>
<p> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]duration[/COLOR] = durationMin*[COLOR=#000080]60[/COLOR][COLOR=#000080]1000[/COLOR];</p>
<p> [COLOR=#808080]
// duration in ms.</p>*[/COLOR]
<p> [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]startTime[/COLOR] = [COLOR=#0000ff]getTimer[/COLOR]COLOR=#000000[/COLOR];</p>
<p> [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]id[/COLOR] = [COLOR=#0000ff]setInterval[/COLOR][COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR], [COLOR=#ff0000]“checkTime”[/COLOR], [COLOR=#000080]1000[/COLOR][COLOR=#000000])[/COLOR];</p>
<p> [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]checkTime[/COLOR]COLOR=#000000[/COLOR];</p>
<p>[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]

Obviously there is a lot more, but i thought i would keep it simple for now.


BUY BUBBLERS

clearInterval() ???

i’ve heard of these. I will put it into practice when i get back to my PC. Thanx matthewjumps.


Extreme vaporizer

hope it works out for ya :wink:

clearInterval shouldnt be too hard seeing as youve already gone to the trouble of storing the setInterval in a variable

this.id = setInterval(this, “checkTime”, 1000);

so therefore

clearInterval(this.id); should work to stop it…

I cant take any credit for that code, it was open source that I have tried to amend to my needs. However, the ClearInterval(this.id); works fine :slight_smile:

Although now I have come accross a similar problem with a different kind of function for my football/soccer game:

[AS]ball.onEnterFrame = function() {
if (ball.hitTest(_root.keeper._x, _root.keeper._y)) {
_root.gotoAndStop(“playersave”);
gotoAndStop(31);
} else
play();
};[/AS]

I have animated a football going into a goal, and I only want this code to apply for a very short time.

[CENTER][/CENTER]

The problem is, that the hitTest function doesnt stop even thouh its not in the timeline anymore. The hitTest function is only in the RED area. The BLUE area is telling the game that a goal HAS been scored.

Perhaps this should be a new thread in the gaming and AI section, But I am assuming if I can tell the game to stop applying the hitTest function properlly it would work.

Preview the game at:
http://www.thatcoolsite.com/forummaterial/game.html

You should see what im babbling on about.

Thanx again Matt, and to anyone else who can help.

Mark


EASY VAPE DIGITAL VAPORIZERS

u can remove an onEnterFrame function using

delete ball.onEnterFrame

is that what u mean?