Skip to main content
chasem68205621
Participant
September 25, 2018
Answered

Can’t get code snippet PlayPause sound on click to work

  • September 25, 2018
  • 1 reply
  • 342 views

i and using Adobe Animate CC with Actionscript 3.0, I have vector graphics on the stage that I have converted to  buttons and I want each button to be able to play seperate audio files on click and be able to pause the audio on the next click. I think the best way to do this is with Code Snippet PlayPause on click. But I keep getting errors in my code. Can y’all help me with this?

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

    According to the error, you're missing a right parentheses in line 21.

    Please fix this first.

    1 reply

    chasem68205621
    Participant
    September 25, 2018

    This is my code:

    /* 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 ("").

    */

    man1_btn.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://Vanillathunder/interviews/dad--whitecollar.mp3"));

    fl_SC = s.play();

    }

    else

    {

    fl_SC.stop();

    }

    fl_ToPlay = !fl_ToPlay;

    }

    JoãoCésar17023019
    Community Expert
    Community Expert
    September 25, 2018

    Hi.

    I just tested your code and it worked.

    Can you show us the error you're getting?

    Regards,

    JC