Copy link to clipboard
Copied
Hello,
I'm trying to create a toggle button that allows users to switch between having music playing or not playing by clicking on a button. However I cannot find a solution that works. Is there anyway for a button to mute all sound from playing in the next frame?
I currently have a start menu whereby music plays - below is the code for that section;
Frame 1 (Main Menu)
stop();
var s:Sound = new JazzyFrenchy_Bensound();
var sc:SoundChannel = s.play();
var s_bool:Boolean = true;
PlayBtn.addEventListener(MouseEvent.CLICK,PlayBtnFrame);
function PlayBtnFrame(e:MouseEvent):void
{
gotoAndStop(2);
}
Frame 2 (Next Menu)
MusicToggle.addEventListener(MouseEvent.CLICK, OffBtnMusic);
function OffBtnMusic(e:MouseEvent):void
{
if(s_bool){
sc.stop();
} else {
sc=s.play();
}
s_bool=!s_bool;
}
OptionsBackButton.addEventListener(MouseEvent.CLICK, BacktoMenu);
function BacktoMenu(e:MouseEvent):void
{
gotoAndStop(3)
if(s_bool){
sc.stop();
} else {
sc=s.play();
}
s_bool=!s_bool;
}
Any responses will be greatly appreciated.
Many thanks.
You can import the SoundMixer with this:
import flash.media.SoundMixer;
then stop all sounds with:
SoundMixer.stopAll();
Copy link to clipboard
Copied
You can import the SoundMixer with this:
import flash.media.SoundMixer;
then stop all sounds with:
SoundMixer.stopAll();
Copy link to clipboard
Copied
I have tried to include the SoundMixer.stopAll() but to no avail.
Copy link to clipboard
Copied
Your script for toggling the sound looks like it should work. Look in the Output panel in case there are errors happening that is stopping it from working correctly.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now