# Stopping a function mid way

**URL:** https://forum.kirupa.com/t/stopping-a-function-mid-way/261717
**Category:** flash
**Created:** [May 30, 2008, 6:21am UTC](https://forum.kirupa.com/t/stopping-a-function-mid-way/261717 "2008-05-30T06:21:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Natushi12](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Natushi12](https://forum.kirupa.com/u/Natushi12)
#### Post date: [May 30, 2008, 6:21am UTC](https://forum.kirupa.com/t/stopping-a-function-mid-way/261717/1 "2008-05-30T06:21:10Z")

</div>

Hey everyone,

I currently have this function in my flash

function wait() {  
gotoAndStop(19);  
clearInterval(myTimer); .  
}  
myTimer = setInterval(wait, 6000);

however, sometimes I leave the page before it times out however it will continue to count down and change to that frame regardless of what im doing. Is there anyway to tell the function that if I leave the page its to stop working?

Natushi12

---

<div class="post-metadata">

### Author: ![creatify](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@creatify](https://forum.kirupa.com/u/creatify)
#### Post date: [May 30, 2008, 6:33am UTC](https://forum.kirupa.com/t/stopping-a-function-mid-way/261717/2 "2008-05-30T06:33:55Z")

</div>

yep - wherever you have the code that tells your movie to go and do something - you need to use:

```
clearInterval(myTimer);

```

to stop that interval from progressing.

---

<div class="post-metadata">

### Author: ![Natushi12](https://avatars.discourse-cdn.com/v4/letter/n/ba8739/32.png) [@Natushi12](https://forum.kirupa.com/u/Natushi12)
#### Post date: [May 30, 2008, 6:38am UTC](https://forum.kirupa.com/t/stopping-a-function-mid-way/261717/3 "2008-05-30T06:38:40Z")

</div>

[quote=creatify;2333460]yep - wherever you have the code that tells your movie to go and do something - you need to use:

```
clearInterval(myTimer);

```

to stop that interval from progressing.[/quote]

cool, thanks
