I have a simple Flash-player button (toggle play/stop) that plays MP3s. When I press play the MP3 starts and the button changes to stop. When I press again the music stops and the stop-button changes to play.
I have several player-buttons on my page. How do I stop all sounds when I press play on one of the buttons? As of now, I can start several MP3 at the same time and I don’t want that. I’ve tried this:
Code:
import flash.media.SoundMixer;
SoundMixer.stopAll();
but it doesn’t work out. Do I need to number the players somehow?
Also, when the MP3 has finished playing it should turn into a play button. As of right now it’s a stop-button when it’s finished playing. How do I change it to a play-button?
This is the Actionscript 3 code:
Code:
var flashVars=this.root.loaderInfo.parameters;
var loadSnd:URLRequest = new URLRequest(flashVars.myVar);
var thisSnd:Sound = new Sound();
var sndTrans: SoundChannel = new SoundChannel();
thisSnd.load(loadSnd);
play_btn.addEventListener(MouseEvent.CLICK,playF);
stop_btn.visible = false;
stop_btn.addEventListener(MouseEvent.CLICK,stopF);
function playF(event:MouseEvent): void{
sndTrans = thisSnd.play();
play_btn.visible = false;
stop_btn.visible = true;
}
function stopF(event:MouseEvent): void{
sndTrans.stop();
stop_btn.visible = false;
play_btn.visible = true;
}