• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Stop sound when same button is pressed

New Here ,
Oct 21, 2011 Oct 21, 2011

Copy link to clipboard

Copied

I'm a complete beginner to any type of programming, so I'm glad that I even got this small tiny script working without errors. I've been scouring the web for tutorials and help and I can't find any tutorial to help. But I know this is a Programming 101 fix, so if anyone

wants to give me any advice, I'd gladly appreciate it.

When I press Btn1 - a sound plays, BUT when i press another button (either Btn2 or Btn1 again) then the sounds overlap each other. Can someone help me

Write an if statement such that when a second button is pressed that the first sound will STOP playing?  Here is what I have, I know my URLRequest could be simplified...but it works and thats all I care about right now.

Thanks in advance!

-David

Untitled.png

Views

416

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 27, 2011 Oct 27, 2011

Copy link to clipboard

Copied

LATEST

David,

I am not an expert, but it looks like you just need to add a line ahead of the new request into each of your 2 functions

channel = sound.stop();

req = new URLRequest("/assets/song1.mp3");

                                        sound = new Sound(req);

                                        channel = sound.play();

BR

peter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines