Skip to main content
Participating Frequently
March 5, 2024
Answered

Unmute/Mute Toggle Button HTML5 Canvas, Adobe Animate

  • March 5, 2024
  • 2 replies
  • 1370 views

Hoping someone can help with this. I can't get it to work to save my life.

 

I have an animation I did years ago in Flash, and am trying to update it in Adobe Animate adding a mute/unmute toggle button and then export it as HTML/Javascript for use on a website.

 

There are 4 different layers of sound effects. I need all the sounds to be muted initially, showing the sound icon with a line thru it so that everyone knows its muted... then when clicked, remove the line and unmute all the sounds.

 

I have searched the discusions here and spent hours trying to figure out how to get this mute toggle button working, but alas, am having no luck at all. The Adobe Animate interface is a lot like the old Flash so I'm finding my way around there, but am really struggling with getting the Actionscript correct and tying it in with the button.

 

Here is a link to the current .FLA file I'm working with: https://drive.google.com/file/d/1lhNfWgcm7tzs0_f3vqe2lM56EIoTx1vq/view?usp=drive_link

This is the Actionscript I'm currently trying to use with the button...

 

var root = this;
var muteButton = root.muteButton;
root.toggleMute = function(e)
{
    createjs.Sound.muted = !createjs.Sound.muted;

    if (createjs.Sound.muted)
        root.toggleButton(e.currentTarget, {out:2, over:2, down:2});

    else
        root.toggleButton(e.currentTarget, {out:0, over:1, down:2});
};

root.toggleButton = function(button, frames)
{
    var listeners = button._listeners;

    if (!listeners)
        return;

    for (var key in listeners)
    {
        var listener = listeners[key][0];      

        if (typeof(listener.outLabel) !== 'undefined')
            listener.outLabel = frames.out;

        if (typeof(listener.overLabel) !== 'undefined')
            listener.overLabel = frames.over;

        if (typeof(listener.downLabel) !== 'undefined')
            listener.downLabel = frames.down;
    }

    button.gotoAndStop(frames.out);
};

muteButton.on("mousedown", root.toggleMute);

 

 

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

    Thank you for sharing that JC! It's a step in a different direction at least. When I tested it, the visual toggle of the button is working, but no toggle of sound.... and my animation isn't playing.


    Sorry.

     

    There's a stop call in the main function. You can remove that.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    March 8, 2024

    Hi.

    Just requested access to the file.

     

    Regards,

    JC

    splitz78Author
    Participating Frequently
    March 8, 2024

    Hi JC, I didn't see a share request in my email or spam from you. Maybe Google is slow at sending those out this morning. Anyway, I did change the privledges on the file so anyone with the link should be able to download.

    https://drive.google.com/file/d/1OM8dosWQK8qle4Fts8TzzMMfwIuVXHiV/view?usp=drive_link

    kglad
    Community Expert
    Community Expert
    March 5, 2024

    just use a boolean to set and check if sounds are muted.

    splitz78Author
    Participating Frequently
    March 5, 2024

    Thanks, I wish that was as easy for me as it sounds, but my programming/actionscript skills are horrible.

     

    I did try the one below before, that I had found in an old Youtube video, and I kinda understood what they were doing with it, but when I added it to my button and plublished to view, the whole animation just went black.

    mute_btn.white_bar.visible=true;
    
    function setVolume(vol){
    	var volTransform:SoundTransform = new SoundTransform();
    	volTransform.volume = vol;
    	SoundMixer.soundTransform = volTransform;
    }
    
    var Mute:Boolean = false;
    mute_btn.addEventListener(MouseEvent.CLICK, toggleMuteBTN);
    
    function toggleMuteBtn(event:MouseEvent){if(Mute==true){Mute = false; setVolume(1);
    	mute_btn.white_bar.visible=false;}
    
    else{Mute = true; setVolume(0);
    	mute_btn.white_bar.visible=true;}
    }

     

    kglad
    Community Expert
    Community Expert
    March 5, 2024

    that last snippet is actionscript 3, not javascript.

     

    anyway, what are the sounds that you want to mute/unmute?  is it just a timeline (with the sounds attached) that you want to play once?  are they button sounds (eg, clicks)?  something else?