I am trying to add a sound loop to my site and I have managed to get the sound to play and I can make two buttons start and stop. But how can I make 1 button that both starts and stops the sound?
Here What I have got.
var snd:Sound = new Sound(new URLRequest("dub.mp3"));
var channel:SoundChannel = snd.play();
var pausePosition:int = channel.position;
var volum:Number=0.2;
var transf:SoundTransform = new SoundTransform();
function setVolume(vol:Number):void {
transf.volume=vol;
channel.soundTransform=transf;
}
setVolume(volum);
function stopSound(event:MouseEvent):void {
channel.stop();
channel = null;
}
mute.addEventListener(MouseEvent.CLICK, stopSound);
function startSound(event:MouseEvent):void {
if (channel == null)
{
channel = snd.play(pausePosition);
}
}
mute.addEventListener(MouseEvent.CLICK, startSound);