Skip to main content
Participating Frequently
November 19, 2014
Answered

Dynamic Flash mp3 player issues

  • November 19, 2014
  • 1 reply
  • 380 views

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;

}

}

This topic has been closed for replies.
Correct answer kglad

enclose your code in an if-statement that ensures it only executes once:

var alreadyExecuted:Boolean;

if(!alreadyExecuted){

alreadyExecuted=true;

// all your code

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 20, 2014

enclose your code in an if-statement that ensures it only executes once:

var alreadyExecuted:Boolean;

if(!alreadyExecuted){

alreadyExecuted=true;

// all your code

}

controlZAuthor
Participating Frequently
November 21, 2014

i tried this, but it still isn't running properly. If i play the music and navigate throughout the different pages, it will work fine, but upon returning to the homepage, the pause button is no longer functional. What line of code would cause this if it executes more than once?

kglad
Community Expert
Community Expert
November 22, 2014

i didn't go through all your code so i can't answer that.

the most common problem would be including an interactive object on more than one keyframe (especially if it's tweened).