Dynamic Flash mp3 player issues
Ok so I have built this mp3 player with a play pause and stop button. Everything works but when I navigate to different parts of the timeline and then return to the home screen, the pause button will no longer work. All my code is on frame 1, which is also the home frame. Here is the code if anyone has any suggestions, that would be awesome!
stop();
//begin button animation
home_button.addEventListener(MouseEvent.ROLL_OVER, overBtn);
home_button.addEventListener(MouseEvent.ROLL_OUT, outBtn);
home_button.addEventListener(MouseEvent.CLICK, clickBtn);
video_button.addEventListener(MouseEvent.ROLL_OVER, overBtn);
video_button.addEventListener(MouseEvent.ROLL_OUT, outBtn);
video_button.addEventListener(MouseEvent.CLICK, clickBtn);
animation_button.addEventListener(MouseEvent.ROLL_OVER, overBtn);
animation_button.addEventListener(MouseEvent.ROLL_OUT, outBtn);
animation_button.addEventListener(MouseEvent.CLICK, clickBtn);
faq_button.addEventListener(MouseEvent.ROLL_OVER, overBtn);
faq_button.addEventListener(MouseEvent.ROLL_OUT, outBtn);
faq_button.addEventListener(MouseEvent.CLICK, clickBtn);
quiz_button.addEventListener(MouseEvent.ROLL_OVER, overBtn);
quiz_button.addEventListener(MouseEvent.ROLL_OUT, outBtn);
quiz_button.addEventListener(MouseEvent.CLICK, clickBtn);
function overBtn(evt:MouseEvent):void{
evt.currentTarget.gotoAndPlay(10);
}
function outBtn(evt:MouseEvent):void{
evt.currentTarget.gotoAndPlay(1);
}
function clickBtn(evt:MouseEvent):void{
evt.currentTarget.gotoAndPlay(20);
}
//end button animation - begin navigation
video_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_13);
function fl_ClickToGoToAndStopAtFrame_13(event:MouseEvent):void
{
gotoAndStop(15);
}
animation_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_14);
function fl_ClickToGoToAndStopAtFrame_14(event:MouseEvent):void
{
gotoAndStop(30);
}
faq_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_15);
function fl_ClickToGoToAndStopAtFrame_15(event:MouseEvent):void
{
gotoAndStop(45);
}
quiz_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_16);
function fl_ClickToGoToAndStopAtFrame_16(event:MouseEvent):void
{
gotoAndStop(60);
}
home_button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_17);
function fl_ClickToGoToAndStopAtFrame_17(event:MouseEvent):void
{
gotoAndStop(1);
}
//end navigation -Begin mp3 player code
var mySound:Sound;
var myChannel:SoundChannel;
var soundIsPlaying:Boolean = false; //prevent play btn overlap
var p:uint = 0;
mySound = new Sound;
mySound.load(new URLRequest("media/onimpulse.mp3"));
btn_play.addEventListener(MouseEvent.CLICK, playSound);
btn_stop.addEventListener(MouseEvent.CLICK, stopSound);
btn_pause.addEventListener(MouseEvent.CLICK, pauseSound);
function stopSound(myEvent:MouseEvent):void {
myChannel.stop();
p = 0;
soundIsPlaying = false;
}
function playSound(myEvent:MouseEvent):void {
if (!soundIsPlaying) {
myChannel = mySound.play(p); //play song location (p)
soundIsPlaying = true;
}
}
function pauseSound(myEvent:MouseEvent):void {
if (soundIsPlaying) {
p = Math.floor(myChannel.position);
myChannel.stop();
soundIsPlaying = false;
}
}