# How do i stop a function?

**URL:** <https://forum.kirupa.com/t/how-do-i-stop-a-function/185537>\
**Category:** flash\
**Created:** [April 14, 2006, 12:18am UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537 "2006-04-14T00:18:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tyg3r](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tyg3r/32/1341_2.png) [@Tyg3r](https://forum.kirupa.com/u/Tyg3r)\
**Post date:** [April 14, 2006, 12:18am UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/1 "2006-04-14T00:18:39Z")

</div>

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](http://bubblers.net/)

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [April 14, 2006, 3:50am UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/2 "2006-04-14T03:50:11Z")

</div>

clearInterval() ???

---

<div class="post-metadata">

**Author:** ![Tyg3r](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tyg3r/32/1341_2.png) [@Tyg3r](https://forum.kirupa.com/u/Tyg3r)\
**Post date:** [April 14, 2006, 10:56pm UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/3 "2006-04-14T22:56:23Z")

</div>

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

* * *

[Extreme vaporizer](http://extremevaporizer.info)

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [April 15, 2006, 2:11am UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/4 "2006-04-15T02:11:15Z")

</div>

hope it works out for ya 😉

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…

---

<div class="post-metadata">

**Author:** ![Tyg3r](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/tyg3r/32/1341_2.png) [@Tyg3r](https://forum.kirupa.com/u/Tyg3r)\
**Post date:** [April 15, 2006, 3:49pm UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/5 "2006-04-15T15:49:03Z")

</div>

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 🙂

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] ![](http://img70.imageshack.us/img70/369/functionissue7dz.jpg)[/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](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](http://vaporizerinfo.com/)

---

<div class="post-metadata">

**Author:** ![matthewjumps](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matthewjumps](https://forum.kirupa.com/u/matthewjumps)\
**Post date:** [April 16, 2006, 6:23am UTC](https://forum.kirupa.com/t/how-do-i-stop-a-function/185537/6 "2006-04-16T06:23:15Z")

</div>

u can remove an onEnterFrame function using

delete ball.onEnterFrame

is that what u mean?
