One Button to turn music ON/OFF

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

:frowning:

TIA

Create a movie clip.

1st Frame contains:

stop() action
Play Button

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

Frame 1 Button actions…

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

Frame 2 Button actions…

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

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

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.

oh no:( hehe

thanks for ur help htough=)

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 :slight_smile:

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! :slight_smile:

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.

Here it is…

http://www.kirupa.com/developer/mx/loading.asp

what is the //playsoundcode

thanks