Mike Mike - 4 months ago 59
Javascript Question

"Mute All" action in Animate CC

I'm trying to make a paged interaction, where at anytime a user can click on a button to take them to any other page. Each page is just a point on the timeline where it stops, and plays the page movieclip. like so:

exportRoot.introEnabled.addEventListener("click", introHandler.bind(this));

function introHandler()
{
//mute all media here?

exportRoot.gotoAndPlay(0); // <-- Frame where page starts
}


My problem comes in where this is an HTML5 Canvas instead of a actionscript thing, meaning that the audio has to be Event synced.

The issue then becomes that when switching pages using
gotoAndPlay()
for each scene, the sound from the previous scene doesn't stop.

Searches bring nothing worth putting on here that's remotely helpful.

I'm wondering if there's a way to mute or stop all playing sounds within a button's function?

**note: each page has about 10 sounds, so just muting or stopping each sound individually would be really annoying.

Answer

To stop all playing sounds, you can just use the static stop method on createjs.Sound.

createjs.Sound.stop();

Note that this will stop every sound that is playing. You can resume any sound instance by calling play() again, but there is no way to resume all.

A better way might be to store played sounds in an array, and when you want to clear them out, iterate the array to stop or pause them individually. When you are done, clear out the array, and start over.

Cheers,