Question

import flash.media.Sound;

var sound1 = new MenuTheme();

sound1.play(1000);

 if(currentFrame == 2(your dedicated frame)
 { 
    sound1.stop();
 }

It comes up with Error TypeError: Error #1006 I want it to stop on the next frame after clicking a button otherwise this error stops everything :(

How to get audio to stop on next scene?

Was it helpful?

Solution

Rather than checking to see if the current frame is 2, I would suggest stopping the sound when the button is clicked, like so (with an example button named buttonToNextFrame):

buttonToNextFrame.addEventListener(MouseEvent.MOUSE_DOWN, goToNextFrame);
function goToNextFrame (e: MouseEvent) {
      sound1.stop();
      //Other stuff you would like done when the button is pressed.
      gotoAndStop(2);
}

If there is a way to bypass the button to get to frame 2 and you still want the sound to stop, then you would have to either:

  • stop the sound in every event/way used to get to frame 2
  • stop the sound directly on frame 2 with a plain sound1.stop()

Let me know if you have any further questions!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top