# One Button to turn music ON/OFF

**URL:** <https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297>\
**Category:** flash\
**Created:** [January 15, 2003, 3:49am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297 "2003-01-15T03:49:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![advan](https://avatars.discourse-cdn.com/v4/letter/a/54ee81/32.png) [@advan](https://forum.kirupa.com/u/advan)\
**Post date:** [January 15, 2003, 3:49am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/1 "2003-01-15T03:49:16Z")

</div>

I’ve tried for hours n hours… I still can’t figure this out:-\

How can I use ONE button to toggle the sound ON or OFF… if the sound is off the button will turn the sound on and if the sound is on and playing, the button will turn the sound off. Pretty straight forward but I am stumped

☹

TIA

---

<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:** [January 15, 2003, 3:53am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/2 "2003-01-15T03:53:56Z")

</div>

Create a movie clip.

1st Frame contains:

stop() action  
Play Button

2nd Frame contains:  
stop() action  
Stop Button.

Frame 1 Button actions…

```auto
on (release){
//play sound code
_parent.gotoAndStop(2);
}

```

Frame 2 Button actions…

```auto
on (release){
stopAllSounds();
_parent.gotoAndStop(1);
}

```

---

<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:** [January 15, 2003, 4:00am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/3 "2003-01-15T04:00:00Z")

</div>

using that method, will my preloader still detect the sound file and preload it?

---

<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:** [January 15, 2003, 4:06am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/4 "2003-01-15T04:06:06Z")

</div>

Yeah.

But please note: If you load the sound through Actionscript (with the linkage property set on the sound file in the library) your sound file will load BEFORE your preloader… leaving you with a pause before your movie actually loads. Unfortunately.

---

<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:** [January 15, 2003, 4:10am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/5 "2003-01-15T04:10:28Z")

</div>

oh no:( hehe

thanks for ur help htough=)

---

<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:** [January 15, 2003, 4:17am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/6 "2003-01-15T04:17:57Z")

</div>

Yeah to the frown on the pausing, it sucks, but the sound does have to load before your movie or else it can’t be called on :-\

No problem though, glad I could help 🙂

---

<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:** [January 15, 2003, 4:24am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/7 "2003-01-15T04:24:30Z")

</div>

the sound on/off button works perfectly.

so… because I load the sound via…

blahSound = new Sound(this);  
blahSound.attachSound(“musicloop”);  
blahSound.start(0, 99);

that means the movie will load the music clip first, THEN start my preloader correct?

thanks for all your help! 🙂

---

<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:** [January 15, 2003, 4:27am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/8 "2003-01-15T04:27:12Z")

</div>

Yep, that is what will happen.

So make sure your sound file isn’t too big.

You can also load sound in dynamically. There is a tutorial on loading techniques here on kirupa if you can find it. All the way at the bottom it shows you how to load sound dynamically into Flash, this could be an alternative if you want.

---

<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:** [January 15, 2003, 4:28am UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/9 "2003-01-15T04:28:06Z")

</div>

Here it is…

[http://www.kirupa.com/developer/mx/loading.asp](http://www.kirupa.com/developer/mx/loading.asp)

---

<div class="post-metadata">

**Author:** ![darkpiece](https://avatars.discourse-cdn.com/v4/letter/d/2acd7d/32.png) [@darkpiece](https://forum.kirupa.com/u/darkpiece)\
**Post date:** [April 23, 2006, 10:08pm UTC](https://forum.kirupa.com/t/one-button-to-turn-music-on-off/11297/10 "2006-04-23T22:08:26Z")

</div>

what is the //playsoundcode

thanks
