# Stop/Start Sound When Frame Reached

**URL:** https://forum.kirupa.com/t/stop-start-sound-when-frame-reached/310
**Category:** flash
**Created:** [July 13, 2002, 3:44am UTC](https://forum.kirupa.com/t/stop-start-sound-when-frame-reached/310 "2002-07-13T03:44:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![NeonGold](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@NeonGold](https://forum.kirupa.com/u/NeonGold)
#### Post date: [July 13, 2002, 3:44am UTC](https://forum.kirupa.com/t/stop-start-sound-when-frame-reached/310/1 "2002-07-13T03:44:38Z")

</div>

Greetings again! Just wanted to know… I’m using multiple background music in the cartoon that I’m making, but I don’t want to go into all the trouble of actually editting the mp3 using another program. So, how do we make it in flash so that when a certain frame is reached, the specified background music will stop or start, and as well as when a certain button is pressed, the music will stop or start.

Thanks a lot people!=)

---

<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: [July 14, 2002, 8:13pm UTC](https://forum.kirupa.com/t/stop-start-sound-when-frame-reached/310/2 "2002-07-14T20:13:21Z")

</div>

Hello **NeonGold** ,

the trick to controlling your sounds with precision is to use ActionScript. Before continuing with an explanation on how this is done, you must make sure that you export your sound from the library. To do this, right-click on the sound you want exported from the library and click _Linkage…_. When a box appears, check the _Export for ActionScript_ box, and enter a relevant name in the _Identifier_ text box. Once that’s done, you’re ready for some ActionScript 🙂

**1. Stopping a sound at a particular frame**  
Assuming your cartoon is inside a movie clip with the instance name _cartoon_ (and is placed on the \_root level) and that you exported your sound as _track1_, attach the following code to your movie clip:

```auto

onClipEvent(load) {
  this.soundTrack = new Sound();
  this.soundTrack.attachSound("track1");
  this.soundTrack.start(0, ***number of loops*** );
  this.soundInit = true;
}

onClipEvent(enterFrame) {
  if(this._currentframe == ***frame to stop sound*** ) {
    this.soundTrack.stop("track1");
  }  
}

```

That should do it.

**2. Starting and stopping sound with a button**  
Make a button and attach the following code to it (I am assuming that you want to start and stop the sound in your movie clip _cartoon_):

```auto

on(press) {
  if(_root.cartoon.soundTrack.soundInit == false) {
    _root.cartoon.soundTrack.start(0, ***number of loops*** );
    _root.cartoon.soundTrack.soundInit = true;
  }

  else {
    _root.cartoon.soundTrack.stop("track1");
    _root.cartoon.soundTrack.soundInit = false;
  }
}

```

And that’s it!

If you encounter any problems, let me know and I’ll work it out.

🙂

-ptolemy

---

<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: [July 14, 2002, 9:43pm UTC](https://forum.kirupa.com/t/stop-start-sound-when-frame-reached/310/3 "2002-07-14T21:43:07Z")

</div>

how can you turn it off with a button?

my movie will have a main interface and it will load its music from other .swfs.

so I wonder which way would be more effective, take less time, or any other advantages

\_root.brian.thank.you
