play stop pause sound AS3
var soundRequest:URLRequest = new URLRequest("soundFile.mp3");
var sound:Sound = new Sound();
var soundController:SoundChannel = new SoundChannel();
sound.load(soundRequest);
var resumeTime:Number = 0;
sound.addEventListener(Event.COMPLETE, onComplete);
function onComplete(event:Event):void
{
play_btn.addEventListener(MouseEvent.CLICK, playSound);
stop_btn.addEventListener(MouseEvent.CLICK, stopSound);
}
function playSound(event:MouseEvent):void
{
soundController = sound.play(resumeTime);
pause_BTN.visible = true;
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_BTN.visible = false;
play_btn.removeEventListener(MouseEvent.CLICK, playSound);
}
function pauseSound(event:MouseEvent):void
{
resumeTime = soundController.position;
soundController.stop();
pause_BTN.visible = false
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
play_BTN.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
}
function stopSound(event:MouseEvent):void
{
soundController = sound.stop();
pause_BTN.visible = false
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
play_BTN.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
}
pause_BTN.visible = false;
תגובות
הוסף רשומת תגובה