Skip to main content
New Participant
April 4, 2019
Question

How can I control Audio with Adobe Animate on a HTML5 canvas?

  • April 4, 2019
  • 1 reply
  • 1170 views

Hi,

creating Actionscript 3 buttons that controlled audio (play/stop) worked fine for me.
But on a HTML5-Canvas I just cant get it to work.
The start/stop options under properties are also not working with HTML5.

This is my buttons action. Does anybody have an idea what I can add to stop a certain MP3 from playing when clicked?

this.negBtn01.addEventListener("click", fl_ClickToGoToAndStopAtFrame.bind(this));

function fl_ClickToGoToAndStopAtFrame()

{

    this.gotoAndStop("01_neg");

    ??????????? ( WHAT CAN I ADD HERE?) ????????????????

}

If the problem can be solved differently, please let me know.

    This topic has been closed for replies.

    1 reply

    avid_body16B8
    Brainiac
    April 4, 2019

    People use different way to control sounds. Below is what I use for example:

    Note: I put my code in frame one.

    Note2:

    play ( src  [interrupt="none"|options]  [delay=0]  [offset=0]  [loop=0]  [volume=1]  [pan=0]  [startTime=null] [duration=null] )

    createjs.Sound.play("reset", "none", 0, 0, 0, 0.5);

    reset is the link name in library.

    function startGame() {

        this.gotoAndStop("game");

        this.music = createjs.Sound.play("music", "none", 0, 0, -1, 0.4);

    }

    Here is an example for a music button:

    //************************* MUSIC BUTTON  ************************

    this.musicBtn.addEventListener("click", musicToggle.bind(this));

    var on = 0;

    function musicToggle() {

        if (on == 0) {

            this.musicBtn.musicStatus.gotoAndStop("musicOff");

            this.music.paused = true;

            on = 1;

        } else {

            this.musicBtn.musicStatus.gotoAndStop("musicOn");

            this.music.paused = false;

            on = 0;

        }

    }

    New Participant
    April 8, 2019

    Thank you resdesign.

    I tried that out but it´s not really working for me that way.

    Let´s say I have an imported audiofile called "speaker.mp3" which is allready playing at some point (audiowave starting at a certain keyframe).
    Now I need a button that doesn´t toggle the sound on and off, but it should only stop that one MP3 from playing.

    Since there is background music, not all sounds should stop.

    Isn´t there a line of code that will just stop that one audiofile from playing?
    Maybe the answer is in your example. But since I have multiple audiofiles a I am looking for a more efficient way of solving this.

    Any ideas?