Assuring a single instance of sound
I have this code:
var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
mySound.load(new URLRequest("audio/audio1.mp3"));
pause_btn.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void{
lastPosition = myChannel.position;
myChannel.stop();
}
play_btn.addEventListener(MouseEvent.CLICK, onClickPlay);
function onClickPlay(e:MouseEvent):void{
myChannel = mySound.play(lastPosition);
}
stop_btn.addEventListener(MouseEvent.CLICK, onClickStop);
function onClickStop(e:MouseEvent):void{
SoundMixer.stopAll();
}
Everything works fine : When I click the play button it starts and resumes sund. But if I accidently press the start buttun twice it brings on two simultaneos sounds. How can I make sure that only 1 instance of sound is playing?
Thanks for any help.