Skip to main content
Participant
December 10, 2010
Answered

Adding two functions to one button (gotoAndPlay, stop sound)

  • December 10, 2010
  • 1 reply
  • 1793 views


Hello everyone! First of all, I`d like to say that i`m total newbie  regarding to as3. Ok, lets look at my problem.. I have 2 scenes (first  is main menu with New Game button; second scene is intro for game). I`m  having difficulties to make two functions within one button. Why do I  need that? First function is to go to next scene (in my case,  IntroScene). Second is for turning off sounds, so I can`t hear them in  next scene.

Here is the code:

var bobobg:bobomusic;
var sndChannel:SoundChannel;

bobobg = new bobomusic;
sndChannel = bobobg.play();

//MAIN MENU BUTTONS - NEW GAME
newgame_btn.addEventListener(MouseEvent.CLICK, buttonClick3);
newgame_btn.addEventListener(MouseEvent.CLICK, buttonClick4);
function buttonClick3(event:MouseEvent):void{
gotoAndPlay(1, "IntroScene");
}
function buttonClick4(event:MouseEvent):void{
bobobg.stop();
}


Error message: "TypeError: Error #1006: stop is not a function.
at MainMenu_fla::MainTimeline/buttonClick4()"

I would really appreciate if some one could help me with this. Thank you!

This topic has been closed for replies.
Correct answer jp311

Yes. At least that I know for sure



Ok good.  Just do this:

var bobobg:bobobgmusic = new bobobgmusic();
var sndChannel:SoundChannel = new SoundChannel();

sndChannel = bobobg.play();

//MAIN MENU BUTTONS - NEW GAME
newgame_btn.addEventListener(MouseEvent.CLICK, buttonClick3);

function buttonClick3(event:MouseEvent):void
{
    gotoAndPlay(1, "IntroScene");
    sndChannel.stop();
}

1 reply

Inspiring
December 10, 2010

Just add one event listener to your button to tell it to go to your next scene and then in the first keyframe of the next scene, put a call in there to stop your sounds.  That way your not trying to add 2 event listeners to 1 button.  Understand?

Jesse

afgsrehAuthor
Participant
December 10, 2010

To tell the truth, I understood only first part of what you said. What exactly do you mean by "put a call in there to stop your sounds"?

Thank you!

afgsrehAuthor
Participant
December 10, 2010

Ok, well think of the way your doing it now with 2 event listeners.  You have 2 functions, 1 to go to the next scene and the other

to stop your sounds.  Rather than having 2 functions, in the first keyframe of your next scene, put the code

that is inside your current function to stop your sounds, there.  So right now you have bobog.stop(); in your second function, but eliminate that function all together and put bobog.stop(); in the first keyframe of your second scene.  Yes?

Jesse


Tried it, but still i`m getting the same error that stop is not a function. Oh, my..