# On/off button for music

**URL:** https://forum.kirupa.com/t/on-off-button-for-music/107059
**Category:** Uncategorized
**Created:** [April 11, 2004, 11:49pm UTC](https://forum.kirupa.com/t/on-off-button-for-music/107059 "2004-04-11T23:49:39Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![CoDe\_ReD](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/code_red/32/336_2.png) [@CoDe\_ReD](https://forum.kirupa.com/u/CoDe_ReD)
#### Post date: [April 11, 2004, 11:49pm UTC](https://forum.kirupa.com/t/on-off-button-for-music/107059/1 "2004-04-11T23:49:39Z")

</div>

Hey Kirupians,

I am working on a website and what I want to do is to add some music to the site. I only want to have one song playing, so all I need is an on/off button. So I created a button and attached this code:

```auto

on (release) {
	if (music=0){
		gotoAndStop(1);
		_root.soundcontent.loadMovie("silence.swf")
		music=1
	}
	else {
		gotoAndStop(2);
		_root.soundcontent.loadMovie("empty.swf")
		music=0
	}
}

```

The gotoAndStop commands are for the button (which is a mc) itself, to change states (sound waves when music is on, red cross when the music is off).  
silence.swf is the name of the swf containing the music (Delerium - Silence, beautifull song btw), empty.swf is just an empty mc to turn the sound off. I also added music=1 to my main timeline so that the music starts playing when the site opens.  
I’m an actionscript noob so I dunno if I’m doing this correct. Maybe I’m just screwing up. Anyway I hope this is still understandable. If anyone needs the .fla file just ask. Hope someone can help me.

Thnx in advance, Code R.
