Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Music buttons - clicking on another music button will stop the music from the one you pressed before

Guest
Sep 21, 2019 Sep 21, 2019

I have a few buttons that if clicked with mouse it will play music, I'm trying to get to where if I play another music button, it will stop the previous music. And if I play another music button it will stop the previous music, etc. If there's a ActionScript code for this, let me know

TOPICS
ActionScript
167
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2019 Sep 22, 2019
LATEST

you can always use SoundMixer.stopAllSounds() to stop all currently playing sounds, though it's often better to use a variable to reference the last played soundchannel and stop it explicitly when playing a new sound.  eg,

 

var currentSoundChannel;

 

function button1F(e:MouseEvent):void{

stopCurrentSoundF();

var s1:Sound1 = new Sound1();

currentSoundChannel = s1.play();

}

function button2F(e:MouseEvent):void{

stopCurrentSoundF();

var s2:Sound2 = new Sound2();

currentSoundChannel = s2.play();

}

etc...

 

function stopCurrentSoundF():void{

if(currentSoundChannel){

currentSoundChannel.stop();

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines