Skip to main content
tjlinzy
Inspiring
July 7, 2023
Question

Stop sound btn using AS3

  • July 7, 2023
  • 2 replies
  • 191 views

This is a pretty easy question.  First, let me say that I am NOT a coder.  The work I do thus far is able to be done quickly and easily with Code Snippets.  However, there is not a snippet for "STOP SOUND" for a button.  The coding for Stopping All Sounds, is not what I need for this project. 

 

Is there such an animal?  Would anyone happen to know where I could get a tutorial on this?  I have searched the web and YouTube, but I only find the tutorials for creating start and stop coding.  

 

The thing is, I created an animated character that talks and blinks, which is all that I need.  The mp3 is streamed and everything works with no problem...until I want to move to the next page BEFORE the puppet stops talking.  As I said, if I use the code snippets stop all sounds, then the puppet on the next frame will not talk.  

 

Any advice? 

Thanks in advance, 

Terri

    This topic is closed to new replies. Start a new post to keep the conversation going.

    2 replies

    Community Expert
    July 8, 2023
     
    /* Click to Play/Stop Sound
    Clicking on the symbol instance plays the specified sound.
    Clicking on the symbol instance a second time stops the sound.
     
    Instructions:
    1. Replace "http://www.helpexamples.com/flash/sound/song1.mp3" below with the desired URL address of your sound file. Keep the quotation marks ("").
    */
     
    movieClip_1.addEventListener(MouseEvent.CLICK, fl_ClickToPlayStopSound);
     
    var fl_SC:SoundChannel;
     
    //This variable keeps track of whether you want to play or stop the sound
    var fl_ToPlay:Boolean = true;
     
    function fl_ClickToPlayStopSound(evt:MouseEvent):void
    {
    if(fl_ToPlay)
    {
    var s:Sound = new Sound(new URLRequest("http://www.helpexamples.com/flash/sound/song1.mp3"));
    fl_SC = s.play();
    }
    else
    {
    fl_SC.stop();
    }
    fl_ToPlay = !fl_ToPlay;
    }
    kglad
    Community Expert
    Community Expert
    July 7, 2023

    you should be able to stop a sound embedded in a timeline that has its sync property set to stream by stopping the timeline.