Mute button for entire hype project

Hi Craig (@craigah13)

It depends on how you've added your audio.

If you've added it by using code or by dragging it onto the scene then you could mute it using the .muted property. For example:

if (audioElement.muted) {
    audioElement.muted = "";
} else {
    audioElement.muted = "true";
}

audioElement is a variable that holds the audio instance so

var audioElement = document.createElement('audio');

or

var audioElement = document.getElementById('myAudio');

in your case you would probably need to collect all your audio in an array

var audioElements = document.getElementsByTagName('audio');
for(var i=0; i < audioElements.length; i++) {
    if (audioElements[i].muted) {
        audioElements[i].muted = "";
    } else {
        audioElements[i].muted = "true";
    }

You could add this Javascript to a button (or any element) using the "On Mouse Click"

This post might help you more.

1 Like