I am working with a short vocal track and when the audio ends I would like a replay button to appear. The codes should work fine, no errors appear. Trace displays nothing…
Here is some of the code:
var clip = “testClip.mp3”;
//Create the Sound & SoundChannel Objs
var soundReq:URLRequest = new URLRequest(clip);
var sound:Sound = new Sound();
var soundControl:SoundChannel = new SoundChannel();
var resumeTime:Number = 0;
sound.load(soundReq);
sound.addEventListener(Event.COMPLETE, onComplete);
soundControl.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
trace(sound.length);
//instants player event listners
function onComplete():void {
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
//player_btn.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
}
//onmouseout event
function playSound(Event:MouseEvent):void {
soundControl = sound.play(resumeTime);
pause_btn.visible = true;
pause_btn.addEventListener(MouseEvent.CLICK, pauseSound);
play_btn.visible = false;
play_btn.removeEventListener(MouseEvent.CLICK, playSound);
}
//onmouseover event
function onMouseOut(Event:MouseEvent):void {
soundControl.stop(); }
function pauseSound(Event:MouseEvent):void {
resumeTime = soundControl.position;
soundControl.stop();
play_btn.visible = true;
play_btn.addEventListener(MouseEvent.CLICK, playSound);
pause_btn.visible = false;
pause_btn.removeEventListener(MouseEvent.CLICK, pauseSound);
}
function onPlaybackComplete(event:Event):void
{
trace(“The sound has finished playing.”);
}