# Sound On/Off Button; Loop; Autoplay

**URL:** https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096
**Category:** flash
**Created:** [June 23, 2008, 6:01am UTC](https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096 "2008-06-23T06:01:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![lippstuh](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@lippstuh](https://forum.kirupa.com/u/lippstuh)
#### Post date: [June 23, 2008, 6:01am UTC](https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096/1 "2008-06-23T06:01:49Z")

</div>

I’m almost done building a full flash site where it navigates by position of timeline.

I just need a simple on/off button for a soundloop to loop and play automatically. the on/off button just simply turns it off (toggle is optional). on it doesn’t have to resume, just start the pool again.

actionscript 3.0 in cs3 please

---

<div class="post-metadata">

### Author: ![DiamondDog](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@DiamondDog](https://forum.kirupa.com/u/DiamondDog)
#### Post date: [June 23, 2008, 7:43pm UTC](https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096/2 "2008-06-23T19:43:03Z")

</div>

You could maybe do it something like this. (.fla attached)

```auto
import flash.media.Sound;
import flash.media.SoundChannel;

var soundOn:Boolean = true; //music is ON when we start
var myMusic:TitleMusic = new TitleMusic();
var myChannel:SoundChannel = myMusic.play(0,1000); // endless loop, in effect
var myTransform:SoundTransform;

mySoundButton.addEventListener(MouseEvent.CLICK,toggleSound);
mySoundButton.buttonMode = true;
mySoundButton.mouseChildren = false;

function toggleSound(e:MouseEvent)
{
    if(soundOn)
    {
        // turn sound off
        myTransform = new SoundTransform();
        myTransform.volume = 0; // silent
        myChannel.soundTransform = myTransform;
        soundOn = false;
        mySoundButton.myButtonText.text = "click to turn sound ON";
    }
    else // sound is off
    {
        // turn sound on
        myTransform = new SoundTransform();
        myTransform.volume = 1; // full volume
        myChannel.soundTransform = myTransform;
        soundOn = true;
        mySoundButton.myButtonText.text = "click to turn sound OFF";
    }
    
}

```

---

<div class="post-metadata">

### Author: ![DiamondDog](https://avatars.discourse-cdn.com/v4/letter/d/74df32/32.png) [@DiamondDog](https://forum.kirupa.com/u/DiamondDog)
#### Post date: [June 23, 2008, 7:53pm UTC](https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096/3 "2008-06-23T19:53:56Z")

</div>

OK, let’s try that ‘fla attached’ thing once more …

---

<div class="post-metadata">

### Author: ![lippstuh](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@lippstuh](https://forum.kirupa.com/u/lippstuh)
#### Post date: [June 23, 2008, 7:59pm UTC](https://forum.kirupa.com/t/sound-on-off-button-loop-autoplay/264096/4 "2008-06-23T19:59:31Z")

</div>

thanks diamonddog, i’ll take a look at it when i get off work… major thanks!
