Skip to main content
joem95179670
Participant
March 12, 2017
Answered

How to make a button in one frame mute all sound/audio in the next frame?

  • March 12, 2017
  • 1 reply
  • 893 views

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.

This topic has been closed for replies.
Correct answer Colin Holgate

You can import the SoundMixer with this:

import flash.media.SoundMixer;

then stop all sounds with:

SoundMixer.stopAll();

1 reply

Colin Holgate
Colin HolgateCorrect answer
Inspiring
March 12, 2017

You can import the SoundMixer with this:

import flash.media.SoundMixer;

then stop all sounds with:

SoundMixer.stopAll();

joem95179670
Participant
March 12, 2017

I have tried to include the SoundMixer.stopAll() but to no avail.

Colin Holgate
Inspiring
March 12, 2017

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.