0

My problem is having several buttons in flash that play sounds when clicked, and I want only one button/sound to be active at a time. Problem is that if the mouse button is released outside of the flash window the last button's sound keeps sounding til the end, and if another button is pressed in the meantime it too starts sounding simultaneously, and so on.

So I thought of checking if the SoundChannel assigned to any other button than the currently pressed one is playing, and if so, stop that SoundChannel to only let the current button's SoundChannel play.

But if this Actionscript SoundChannel is a single object for all the buttons, this won't work, and then I don't see a solution to preventing multiple sounds sounding simultaneously other than adding a 'warning' box, which seems redundant and ineffective. So can you have a separate SoundChannel for each button or object in a flash movie, otherwise how can I bulletproof this so that only one button sound can sound at once no matter where the mouse is released, inside as or outside of the flash window?

user3274901
  • 21
  • 1
  • 5

1 Answers1

0

Can you put the buttons in a container and addEventListener for MouseEvent.MOUSE_UP and in the handler to check if it cursor is outside the container like so:

   private static function onMouseDownOutside(event:MouseEvent) : void {
         var mouseDownInsideComponent : Boolean = false;
         mouseDownInsideComponent = yourContainer.hitTestPoint(event.stageX, event.stageY, false);

         if (!mouseDownInsideComponent) {
            //stop the sound
         }
   }

and just to stop the sound when it gets out of the container? Seems like a possible workaround.

s-rusev
  • 150
  • 1
  • 11
  • So, mouseDownInsideComponent tests for the stage's position? And if false, it means the mouse is outside it? Might take a closer look. – user3274901 Jun 20 '14 at 00:18
  • Actually, and strangely, I've noticed that MOUSE_UP Does fire outside the flash window/stage Inside adobe flash. It's in the web browser that it doesn't fire once clicked and moved outside the flash object area. Maybe I should re-ask this question, but differently? – user3274901 Jun 20 '14 at 07:19