Hi guys i wonder if anyone can help me. ive got a button that when you press it it an audio file plays, a button to pause it and a button to stop it. i think ive got all the code for this working. my problem is that when the audio comes to the end id like the play button to be made visible and the audio to play from the begining again when you press play.
heres my code
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.*;
var soundReq:URLRequest = new URLRequest(“free_fade.mp3”);
var sound:Sound = new Sound();
var soundChannel:SoundChannel = new SoundChannel();
var soundPosition:Number = 0;
sound.load(soundReq);
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 {
soundChannel = sound.play(soundPosition);
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 {
soundPosition = soundChannel.position;
soundChannel.stop();
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
}
function stopSound(event:MouseEvent):void {
soundChannel.stop();
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
soundPosition = 0;
}
pause_btn.visible = false;
//****
soundChannel.addEventListener(Event.SOUND_COMPLETE , soundComplete);
function soundComplete(pevent:Event):void {
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible =false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
soundPosition = 0;
}