Folks
How do u pause music which is looping-
My code below works fine but fails once the music loops. I’m doing something wrong here-
var soundreq:URLRequest = new URLRequest("…/sound/music2.mp3");
var sound:Sound = new Sound();
var sndControl:SoundChannel = new SoundChannel();
var sndVol:SoundTransform = new SoundTransform(0.2, 0);
sound.load(soundreq);
var resumeSnd:Number = 0;
var btnState:Number = 0;
// button to play & pause
sndbars.buttonMode = true;
sndbars.enabled = true;
sound.addEventListener(Event.COMPLETE, playSound);
function playSound(event:Event):void
{
sndControl = sound.play(resumeSnd, int.MAX_VALUE);
sndbars.addEventListener(MouseEvent.CLICK, soundStatus);
sndControl.soundTransform = sndVol;
}
function soundStatus(e:MouseEvent):void
{
if (btnState==1)
{
sndbars.play();
sndControl= sound.play(resumeSnd, int.MAX_VALUE);
sndControl.soundTransform = sndVol;
btnState =0;
}
else
{
// the flaw is in this next line. if i remove it then the music will play normally from start
resumeSnd = sndControl.position;
sndControl.stop();
btnState =1;
sndbars.stop();
}
}
Any insight would be of great help. Thx.