I've created a on/off button for sound using Flash AS3. These work but whenever I press the off button and then the on button, the music doesn't play again?
I believe it's a looping issue but could I be wrong? I'm not sure what code to use if it is a loop problem.
I also need to add code for the btnOn function as when I open the .swf the sound automatically plays.
Attached is my current code below:
var mySound:Sound = new sandstorm(); //(sandstorm is my sound file)
var myChannel:SoundChannel = new SoundChannel();
var lastPosition:Number = 0;
myChannel = mySound.play();
btnOff.addEventListener(MouseEvent.CLICK, onClickPause);
function onClickPause(e:MouseEvent):void {
lastPosition = myChannel.position;
myChannel.stop();
}
Cheers :)
myChannel = mySound.play();
? If you want something to happen only when you click, then put that instruction inside a click handling function. PS: Is functiononClickPause
the one expected to both pause & resume the audio? – VC.One