Mute Sound Button HTML5
Hi. Could someone simply explain how to create a mute sound button (ideally start/stop) in Animate html5 canvas please?
Do I place the audio on the timeline?
Hi. Could someone simply explain how to create a mute sound button (ideally start/stop) in Animate html5 canvas please?
Do I place the audio on the timeline?
Hi.
The easiest way is to use the static propety muted of SoundJS. In this way, you can mute all sounds, no matter how you brought them (placing in the timeline, loading from an external source...).
Then you change this property with a button press.
JavaScript code:
var root = this; // here we store a reference to the main timeline
var muteButton = root.muteButton; // here we store a reference to the mute/unmute button
root.toggleMute = function(e)
{
createjs.Sound.muted = !createjs.Sound.muted; // here we invert the sound state (muted/unmuted)
if (createjs.Sound.muted)
root.toggleButton(e.currentTarget, {out:2, over:2, down:2}); // set the same frame number to the main button states (out, over, and down)
else
root.toggleButton(e.currentTarget, {out:0, over:1, down:2}); // reset the button frames
};
// convenience/utility method to toggle default button symbols instances on and off
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); // mouse down listener added to the mute/unmute button
FLA download:
animate_cc_html5_canvas_mute_all_sounds.zip - Google Drive
Regards,
JC
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.