Stop sound when same button is pressed

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

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

Similar Messages

  • My iPhone 6 wont come on when home button is pressed and screen pixels out and fades.  Any one have fix or same problem?

    My iPhone 6 wont come on when home button is pressed and screen pixels out and fades.  Any one have fix or same problem?
    When I press the home page the screen activates but stays black.  I have to press the side button to turn if off then may have to repeat several times to get my phone to come on.  Sometimes while using the phone the screen will become pixelly and start to fade away leaving a white screen with vertical line on it.  I have to use the close button to make it go away.

    If one of the two major buttons of your phone is broken, it is unfair to expect normal operation to be available. The first resolution to any problem involves a usable Home button, as does the second option for resolving any problem.  Get your Home button fixed.

  • Why do I get the 'critical stop' sound when I leave the firefox browser - doesn't happen with explorer?

    Why do I get the 'critical stop' sound when I leave the firefox browser. This doesn't happen when using internet explorer?

    Do you mean that there is a problem with closing Firefox?
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem (switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance).
    *Do NOT click the Reset button on the Safe Mode start window or otherwise make changes.
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Try to use "Firefox > Exit" (Windows: Firefox/File > Exit; Mac: Firefox > Quit Firefox; Linux: Firefox/File > Quit) to close Firefox if you are currently doing that by clicking the close X on the Firefox title bar.

  • Unlike IE When back button is pressed it takes too long. pleas do something for that. thnx.

    Unlike IE When back button is pressed it takes too long. pleas do something for that. I like firefox and i get to use the back button more often.
    thnx

    In order to be able to find the correct solution to your problem, we require some more non-personal information from you. Please do the following:
    *Click the Firefox button at the top left, then click the ''Help'' menu and select ''Troubleshooting Information'' from the submenu. If you don't have a Firefox button, click the Help menu at the top and select ''Troubleshooting Information'' from the menu.
    Now, a new tab containing your troubleshooting information should open.
    *At the top of the page, you should see a button that says "Copy text to clipboard". Click it.
    *Now, go back to your forum post and click inside the reply box. Press Ctrl+V to paste all the information you copied into the forum post.
    If you need further information about the Troubleshooting information page, please read the article [[Use the Troubleshooting Information page to help fix Firefox issues]].
    Thanks in advance for your help!

  • Changing Navigation when cancel button is pressed

    Hello All,
    We are having custom responsibility for Offer and vacancy creation. New Menu of type(App Pref Menu Container) is created and the required functions and sub menus are attached to it. This was done earlier by someone else. Now when ever i start a transaction (i.e. create offer) and then cancel it, it goes to the custom home page of that responsibility. Now i want to change the navigation page when cancel button is pressed. I believe it was achieved through menu only. Can anyone suggest how?
    Thanks and regards,
    Pradeep

    If a user is halfway ....Look at it this way...Various wizard pages insert rows into various tables. Mark all of them (or some appropriate "master" record) with a "Pending" flag.
    Pressing Cancel is nothing special, just like closing your browser window, the Pending data would continue to hang around.
    You could set up background jobs that purge pending data older than N days or something if you like.
    What I was suggesting was that the "start wizard" button/process should first delete all these Pending rows before starting its real work.

  • Add a new check box when a button is pressed??

    I was trying to add a check box dynamically when a button is pressed.
    The check box contains title and a textbox for the user to enter data.
    For example , when the user hits addnew button , a new check box (title-name)
    with a textbox for entering name should appear on the form.
    Please help
    thanks

    ganeshpuppala wrote:
    Hi ,
    Thanks for the reply , I want to just do the task in java script.
    Can you explain with an example.
    thanksSince you are on a Java forum, I can only assume you want to be talked out of using JavaScript. And since you didn't indicate your choice of GUI toolkit, the default assumption is that you want to use Swing. Congratulations! Start here:
    [http://java.sun.com/docs/books/tutorial/]

  • Matchcode in OO (call the search help when the button is pressed )

    Hi Guys,
    I'm using the class cl_dd_document in order to fill a form that contains a input element (cl_dd_input_element) and a button element (cl_dd_button_element).
    What I need to do now is to simulate (or build) a matchcode for the button.
    For example, the input field is for entering the name of a table, and with the button i want to show all the tables that are elegibles for that field.
    Any suggestion?
    Regards,
    Eric
    Message was edited by:
            Eric Hernandez Pardo

    Hi Uwe,
    What I want to know is how to call the search help when the button is pressed. (Like the one in SE80 Transaction)
    Regards,
    Eric
    Message was edited by:
            Eric Hernandez Pardo

  • Detect when a button is pressed for more than a certain period of time

    How do I detect if a button is pressed for more than a certain amount of time? E.g. if you press on the delete button on the dialer and hold it there, it continues to delete. Or if you hold down the .com button for more than a sec, it changes to .net and so forth.
    Thanks

    Start a timer when the button is pressed. Reset the timer when the button is released. If the timer expires before being reset then you know the button has been held down at least as long as the timer was set for.

  • Create a validation that runs when a button is pressed

    Hi good people from this forum, I was wondering if it's possible to create a validation that runs when a button is pressed.
    I'm using Oracle Apex 4.2.2 with Oracle Apex Listener 2.0 and Oracle Database XE 11g
    Thank you so much for your time
    P.S. On another note, How can I change my display picture =P?

    You can create a validation and give it's condition like 'When Button Pressed' and select a button name or select the Condition Type as 'Request=Expression1' and give request(button name) in Expression1.
    Thanks
    Lakshmi

  • Stop sound when another sound plays

    Hey guys,
    Using Flash Pro CC 2014, Actionscript 3
    I am working on a soundboard and use buttons that play sounds, and I want to make it that when a new sound plays, it automatically stops the current sound from playing, that way 2 sounds dont play at same time.
    But I also have a button that stops all sounds, I am using the "Click to Stop All Sounds" code under Audio and Video in the Code Snippets.
    So I am basically wanting to make sure I can do both, keep the stop all sounds button, but also have it when you press any sound button, it stops all sounds and starts playing the current button/sound. Any suggestions?
    BTW I am setting up symbols as buttons, not movie clips incase you need to know for coding, but I can switch to movie clips if its easier. I was just used to buttons on older versions of Flash for simple stuff like this.
    Thanks.

    Thanks for the reply, I am new to actionscript 3 but am a fast learner. Maybe I am doing this wrong, but when I add the code it simply stops the sounds, but it wont play the sound from the button that I just clicked on. I want it to play the sound button clicked on, and also stop any other sounds that are currently playing.
    For Flash 8, as2, I would add this to the button:
    on (press)
        stopAllSounds ();
    On as3, does it need to say this?
    button_2.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds);
    function fl_ClickToStopAllSounds(event:MouseEvent):void
        SoundMixer.stopAll();
    thanks for your help

  • Need help w/ making an object appear WHEN a button is pressed

    I've tried to figure this out on my own, but am stumped. I even tried using the .setVisible command... but that didnt work. What I would like to happen is to just have the stick figure appear, sans clothing. Then when the "Add Shirt" button is pressed I want the stick figure to acquire a shirt. Same goes for pants.
    import java.awt.event.*;
    import java.awt.*;
    import java.applet.*;
    public class dolls extends Applet implements AdjustmentListener, ActionListener {
         Shirt myShirt;
         Pants myPants;
         Color c;
         Scrollbar red,green,blue;
         int redValue, greenValue, blueValue, clothing = 0;
         Label redColor, greenColor, blueColor;
         Button shirt, pants;
         boolean clickedShirt = false, clickedPants = false;
         public void init(){
              redColor = new Label("Red");
              add(redColor);
              red = new Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256);
              add(red);
              red.addAdjustmentListener(this);
              greenColor = new Label("Green");
              add(greenColor);
              green = new Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256);
              add(green);
              green.addAdjustmentListener(this);
              blueColor = new Label("Blue");
              add(blueColor);
              blue = new Scrollbar(Scrollbar.HORIZONTAL,0,0,0,256);
              add(blue);
              blue.addAdjustmentListener(this);
              shirt = new Button("Add Shirt");
              add(shirt);
              pants = new Button("Add Pants");
              add(pants);
              myShirt = new Shirt(120,125,3);
              myPants = new Pants(120,125,3);
         public void adjustmentValueChanged(AdjustmentEvent e){
              redValue = red.getValue();
              greenValue = green.getValue();
              blueValue = blue.getValue();
              repaint();
         public void paint(Graphics g){
              g.drawOval(150,100,30,30);
              g.drawLine(165,130,165,180);
              g.drawLine(165,133,120,160);
              g.drawLine(165,133,210,160);
              g.drawLine(165,180,143,235);
              g.drawLine(165,180,187,235);
              if(clickedShirt = true) {
                   c = new Color(redValue, greenValue, blueValue);
                   g.setColor(c);
                   myShirt.display(g);
              if(clickedPants = true){
                   clickedPants = true;
                   c = new Color(redValue, greenValue, blueValue);
                   g.setColor(c);
                   myPants.display(g);
         public void actionPerformed(ActionEvent ae){
              if(ae.getSource() == shirt)
                   clickedShirt = true;
                   repaint();
              if(ae.getSource() == pants)
                   clickedPants = true;
    // <applet code = "dolls.class" height = 300 width=350> </applet>If needed I will post the code for the shirt and pants classes.
    Thank you all for your help.

    code for pants.class
    import java.awt.*;
    public class Pants {
         Polygon pants;
         public Pants(int h, int v, int size){
              pants = new Polygon();
              pants.addPoint(10*size+h,18*size+v); // 1
              pants.addPoint(20*size+h,18*size+v); // 2
              pants.addPoint(25*size+h,35*size+v); // 3
              pants.addPoint(18*size+h,35*size+v); // 4
              pants.addPoint(15*size+h,27*size+v); // 5
              pants.addPoint(13*size+h,35*size+v); // 6
              pants.addPoint(05*size+h,35*size+v); // 7
         public void display(Graphics g){
              g.fillPolygon(pants);
    }code for shirts.class
    import java.awt.*;
    public class Shirt {
         Polygon shirts;
         int h;
         public Shirt(int h, int v, int size){
              shirts = new Polygon();
              shirts.addPoint(12*size+h,1*size+v); // 1
              shirts.addPoint(18*size+h,1*size+v); // 2
              shirts.addPoint(29*size+h,9*size+v); // 3
              shirts.addPoint(26*size+h,12*size+v); // 4
              shirts.addPoint(20*size+h,8*size+v); // 5
              shirts.addPoint(20*size+h,20*size+v); // 6
              shirts.addPoint(10*size+h,20*size+v); // 7
              shirts.addPoint(10*size+h,8*size+v); // 8
              shirts.addPoint(4*size+h,12*size+v); // 9
              shirts.addPoint(1*size+h,9*size+v); //10
         public void display(Graphics g){
              g.fillPolygon(shirts);
         public void changeH(int changeHpos){
              h = h + changeHpos;
    }

  • IPod Touch turns off when lock button is pressed.

    My father accidentally put my dog's cage on top of my iPod Touch...surprisingly it was fine. Or so I thought. A few minutes later the volume started acting strange, which I think was a problem with the button. Somehow I fixed that after playing around with it. But when I pressed the lock button, the iPod turned off, and wouldn't turn back on, as if it had no battery life whatsoever. When I got home, I plugged it in, and thankfully it responded. I thought it was fine, until I tried to press the lock button again. It completely dies every time the button is pressed. Which I suppose is alright, as long as I never press that button again but that's rather annoying. Any ideas on what to do with that?

    Sounds like you have a internal connection problem in the iPod. I would make an appointment at the Genius Bar of a local Apple store.

  • HP Palion dv7 Notebook PC will not power up when power button is pressed.

    My HP Pavilion dv7 Notebook PC will not  power on when the power button is pressed. I have removed the battery, unplugged the AC adapter and pressed the power button for 15+ seconds then plugged in the AC adapter and pressed the power button for 15+ seconds. Then I release the power button and then press the power button again and the Notebook will power up and operate normally. I can reinstall the battery once it has powered up. What is causing this problem and how do I remedy the problem?

    Hello Griff83147,
    Unfortunately there could be a number of different things that caused that issue from drivers, software, possibly hardware. I am glad you got it up and running but there isn’t a clear picture of what actually caused. If a technician got the chance to work on it then they could at least narrow it down.
    Sorry I could not answer your question, but this is one of those questions that can have multiple answers.
    If you have any further questions don’t hesitate to ask.
    Thanks  
    Clicking the White Kudos star on the left is a way to say Thanks!
    Clicking the 'Accept as Solution' button is a way to let others know which steps helped solve the problem!

  • Disable page display when back button is pressed after logout

    hi,
    I dont want the old pages to appear once the back button is pressed after loggin g out. That is .... when logged in, if the user presses back button then his previous pages must be shown....but once the user logs out and then if he presses back button then some message like session has been closed....like message should be displayed.
    Hope you understood the problem

    If you expire a page then back button will not take it to the previous page.
    expire is a HTTP-EQUIV meta tag in the header of the page. You can set the content to some time in the "past" when serving the page first time.
    Expires
    This tells the browser the date and time when the document will be considered "expired." If a user is using Netscape Navigator,
    a request for a document whose time has "expired" will initiate a new network request for the document.
    An illegal Expires date such as "0" is interpreted by the browser as "immediately." Dates must be in the RFC850 format, (GMT format):
    <META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT"> Hope this works for you, there are browser dependencies as well.
    vr,
    Sudhakar B.

  • PulseAudio stops sounding when I switch to other display (Ctrl+Alt+F1)

    Hello.
    When I am playing any sound and I switch to a display (Ctrl+Alt+F1, Ctrl+Alt+F2...) where I have not loged in or a am not loged with my default user account, the sound stops, and when I switch back, I continues sounding.
    Anyone have an idea of what could be causing this?
    Thanks.

    Thanks for the reply.
    Is there a way to change that behavior?
    Edit: After killing console-kit-daemon, sound works on all displays, but I think that it is not the best solution.
    Last edited by eduardosm (2011-12-02 21:29:57)

Maybe you are looking for