# Stopping a function with a button?

**URL:** https://forum.kirupa.com/t/stopping-a-function-with-a-button/297344
**Category:** Uncategorized
**Created:** [September 30, 2009, 4:15pm UTC](https://forum.kirupa.com/t/stopping-a-function-with-a-button/297344 "2009-09-30T16:15:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jholly](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jholly](https://forum.kirupa.com/u/jholly)
#### Post date: [September 30, 2009, 4:15pm UTC](https://forum.kirupa.com/t/stopping-a-function-with-a-button/297344/1 "2009-09-30T16:15:10Z")

</div>

Hi,

I appreciate any help, I’m pretty new to flash, and slowly working my way through it!

I’m trying to create a simple ‘drum machine’ game, where certain keys trigger sounds. I have that part down, but now I am trying to add different ‘kits’. I was attempting to do this by simply creating a button to advance to a different frame on my timeline, with different actionscript that calls the new sounds in.

This is my simple AS to play a sound.

```auto
//KICK
var sndKick1:Kick1 = new Kick1();
stage.focus = this;
addEventListener(
    KeyboardEvent.KEY_DOWN,
    function(evt:KeyboardEvent):void {
        switch(evt.charCode) {
            case 75:
            case 107:
                sndKick1.play(1);
                kick_mc.play();
                break;
        }
    }
);

```

The problem I’m having though, is that when I hit the button to advance to a new frame, with different AS, the previous functions are still active, and the sounds overlap. So I need my button to somehow stop the function (seen above) and gotoAndPlay the next.

Let me know if that makes any sense!
