# Stop function from running

**URL:** <https://forum.kirupa.com/t/stop-function-from-running/27868>\
**Category:** flash\
**Created:** [August 7, 2003, 12:11pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868 "2003-08-07T12:11:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danneman](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Danneman](https://forum.kirupa.com/u/Danneman)\
**Post date:** [August 7, 2003, 12:11pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/1 "2003-08-07T12:11:33Z")

</div>

I want to be able to stop a function from running by the press of a button.

Is there such an inbuilt function?  
Like “stop function(myFunction);” or something…?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 12:18pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/2 "2003-08-07T12:18:01Z")

</div>

where is it running?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 3:17pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/3 "2003-08-07T15:17:45Z")

</div>

Its running in a swf that is loaded to the main swf with the loadMovieNum() function.

It can be accessed via \_root.myFunction().

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 3:28pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/4 "2003-08-07T15:28:45Z")

</div>

what does the function do?

if you want to stop it from running always, you can just do this:

```auto

myButton.onRelease = function(){
_root.myFunction = null;

//or:

_root.myFunction = function(){
}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 7, 2003, 3:56pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/5 "2003-08-07T15:56:54Z")

</div>

i’d make the function dynamic (as in you assign the function from somewhere else, not on the actual object or whatever), this way, you can delete it when you want…like…

```auto
mc.onEnterFrame = function () {
trace("what's the best way to annoy you?");
};

```

then later on…

```auto
delete mc.onEnterFrame;

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 8, 2003, 3:47pm UTC](https://forum.kirupa.com/t/stop-function-from-running/27868/6 "2003-08-08T15:47:53Z")

</div>

Well, I dont want to remove the function, I just want to stop it from executing if its in the middle of execution.

It is a rather large function that takes some time in executing, and it is called every time I change to a new page (browser arrows). So when I update with the next/previous page, the same function is called again, but with slightly different parameters (overloading).

The problem Im having now, though, is that if the function is in the middle of execution, and it is called again at that time (overloaded), the first instance of the function (the one running) will not stop executing, but continue along with the execution of the next function-call.

So what I really want is for the browser-button to FIRST stop the running function, and THEN call the function again (with new parameters).
