From: Lucky Kitty on
I have a multi-scene presentation. The first scene includes background music
that is to play throughout the rest of the scenes. I'd like to add a mute
button that would toggle between playing the background music and not playing
the music and still let the rest of the scenes play. How do I do this?

From: uomoDiCuore on
On the button, attach actionscript to include a boolean. Something like
this.onRelease(){
if(mute=false{ //if sound is currently playing
_root.mySound.stop(); //stop playing sound
mute=true; //toggle the mute button
}
else { //meaning that mute=true and sound is currently stopped
_root.mySound.start(); //start playing sound
mute=false; //toggle the mute button
}
}

From: David Stiller on
Lucky Kitty,

> I have a multi-scene presentation. The first scene includes
> background music that is to play throughout the rest of the
> scenes. I'd like to add a mute button that would toggle
> between playing the background music and not playing the
> music and still let the rest of the scenes play.

I searched "sound toggle" at macromedia.com and found several technotes,
including this era-Flash 5 solution, which still works fine.

http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_14821

You'll have to experiment to see if this works for you across Scenes (it
may not). What does work across Scenes is to instantiate the Sound class
and manage your audio via ActionScript. Look up the "Sound class" entry of
the ActionScript Language Reference to see all the details you'll need. In
programming terms, a class is something that defines an object -- and
everything in ActionScript is an object. Movie clips, text fields, and
buttons are objects. And audio is an object. Every object has its own
functionality, the things that make it what it is -- things it can do,
characteristics it has, and things it can react to -- and these are defined
as methods, properties, and events by a namesake class.

When you drag a movie clip from the Library to the Stage, you have
instantiated (made an instance of) the MovieClip class. Movie clips are
visual objects, so you can instantiate them "by hand" like this. Of course,
you can also create movie clips via ActionScript, and the same goes for
audio. Create a variable to hold a reference to the instantiated object ...

var myAudio:Sound = new Sound();

The var keyword indicates you're creating a variable. The myAudio is
the name of your variable (call it what you like). The :Sound suffix
specifies the type of object this is (an instance of the Sound class). The
keyword "new" constructs an instance of some class -- and the Sound() part
means the class in question is the Sound class. From this point forward,
the variable myAudio may be used to accomplish anything listed as a method,
property, or event of the Sound class.

For example, look at Sound.attachSound() ...

myAudio.attachSound("LibrarySoundHere");

By using our Sound instance, we have access to the Sound.attachSound()
method, which attaches a sound asset from the Library to the Stage, as if
you put it there by hand. The sound asset needs a Linkage id, which you can
provide by right clicking and supplying yourself. This id is the string
used as a parameter of the method. This second line of ActionScript means
that our Sound isntance, myAudio, is now "attached" to a particular sound
asset from the Library.

Now you may call on the Sound.start() method.

myAudio.start();

And, of course, you may call on the Sound.stop() method, too, as you
please.

Read through the Language Reference to see all the capabilities and
limitations of the Sound class. Note that the Sound class constructor ...
new Sound(); ... accepts an optional parameter, which is specified as an
object, a movie clip.

var myAudio:Sound = new Sound(this);

.... the word "this" refers to the timeline or object it's in -- so if the
above line of code appears in a frame of the main timeline, "this" refers to
the main timeline, which means your main timeline is the movie clip being
passed as a parameter. You could also pass the instance name of any other
movie clip, which would channel the audio to a particular clip, allowing you
to change volume, etc. to that one sound rather than all sounds at once.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."


From: David Stiller on
> What does work across Scenes is to instantiate the Sound
> class and manage your audio via ActionScript. Look up
> the "Sound class" entry of the ActionScript Language
> Reference to see all the details you'll need.

Ah, I got carried away in my excitement for the Sound class. I failed
to suggest way to make a single toggle that both starts and stops a sound.
uomoDiCuore already covered it in another post on this thread. Basically,
create a Boolean variable (true/false) and use that to determine which Sound
method to employ.

When you click the button, check the variable to see how to act (via an
if() statement), then set the variable to its own opposite.


David
stiller (at) quip (dot) net
"Luck is the residue of good design."


From: Lucky Kitty on
I tried this code for a toggle mute/unmute button, but get an error. What do
you suggest?

on (release)
if(mute=false{
stopAllSounds();
mute=true;
}
else {
startAllSounds ();
mute=false;
}
}