Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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();
}
}