2 Replies Latest reply on Jan 29, 2016 3:15 PM by robdillon

    How to start and stop sounds in Flash with Actionscript 3

    mentalcase129 Level 1

      I'm making a website in Flash.  I want a song to start when a button is pressed.  I tried using the "click to play/stop sounds" preset in the code snippets.  It wants me to use a URL to reference the sound.  I understand in theory how this would work when the website is live but right now as I am making and testing the site I would like to be able to hear the sound when the button is clicked.  Is there not a way to reference as sound file that I've imported directly into Flash?  Can I not somehow assign it an instance name and make it stop and play like I would a movieclip?  Please advise.



        • 1. Re: How to start and stop sounds in Flash with Actionscript 3
          mentalcase129 Level 1

          Another note to add.  The sound I want to play is supposed to play at the same time as animation that plays in a movie click when a button is clicked.  So another way to approach this would be to have the sound on the timeline within that movie clip so that it doesn't play until the animation is told to play by clicking that button.  This would mean adding some sort of code to the root timeline though that tells that sound to not play because it is right now, even with the movieclip stopped the sound still wants to play.

          • 2. Re: How to start and stop sounds in Flash with Actionscript 3
            robdillon Most Valuable Participant

            The reason that you see references to playing a sound that is downloaded at runtime, is that that method is better in terms of user experience. If you have a sound file imported into your movie, then the download will appear to stall while the sound file(s) are downloading. The same happens for imported video. The solution, or workaround, is to download sound files as external files after the initial Flash movie is downloaded.


            In any case, if you want to play a sound that is imported when a button symbol is used, then you can simply add the sound to the button's timeline at the Down frame. Since you're playing the sound from the timeline, you'll have no real control over the volume or stopping the sound.


            If you want to control the sound using Actionscript, then here's a tutorial that may help to explain the process: AS3: Sounds