Skip to main content
Participating Frequently
May 16, 2006
Question

Sound in Movie

  • May 16, 2006
  • 16 replies
  • 847 views
I added a mute button to my movie and created a layer, on the main stage with the "ON click turn off all sounds" script, that will turn all sound off when the button is clicked. (on click). The problem is there are 5 more layers of sound within an All movie clip (there are actually 40 more layers in the clip of various functions). When I'm in the All movie clip, I'm not able to select my Mute button, as it doesn't show up there, since I added the button after the All movie clip was made (this was actually a template I purchased). Does the button have to be added to the All Movie clip so I can select it to then attache the ON click script? If so, how do I add it.
Thanks in advance.
This topic has been closed for replies.

16 replies

May 20, 2006
No need for the 1 after Sound... nor the repeated volumeOn = !volumeOn;

var volumeOn:Boolean = true;
var globalVolume:Sound = new Sound();
btnMute.onRelease = function() {
if (volumeOn) {
globalVolume.setVolume(0);
} else {
globalVolume.setVolume(100);
}
volumeOn = !volumeOn;
};
gorcoAuthor
Participating Frequently
May 20, 2006
Hi again,

Sorry, but I just can't get this to work. When I mouse over the layer that contains the sound wave, in my time line, a yellow box pops up with the label: "Sound: Sound 1"

So it's my understanding the sound instance name is "Sound 1" (is that correct?). Also, my Mute button instance name has been renamed to "btnMute". Based on this, I wrote the following code:

var volumeOn:Boolean = true;
var globalVolume:Sound 1 = new Sound();
btnMute.onRelease = function() {
if (volumeOn) {
globalVolume.setVolume(0);
} else {
globalVolume.setVolume(100);
}
volumeOn = !volumeOn;
}
volumeOn = !volumeOn;

When I test for errors, I get the following error message:

Scene=Scene 1, Layer=Mute Sound, Frame=1: Line 2: ';' expected
var globalVolume:Sound 1 = new Sound();

Question: I'm not sure what this means.....
Inspiring
May 19, 2006
gorco,

> Sorry, but I tried modifying code but the sound in my
> movie doesn't get turned off.

We'll keep working at it until it makes sense.

> I only have one button, in which I named the instance
> "Mute".

Okay.

> Is this the way the code should be written?:

Looking ...

> var volumeOn:Boolean = true;
> var globalVolume:Sound = new Sound();

So far, so good. Your variable volumeOn refers to a Boolean object
whose value is true. In effect, you could call your variable an "instance
name" of the Boolean object. (There is, after all, a Boolean class in
ActionScript, and any variable that is a Boolean object is an instance of
the Boolean class -- just like any movie clip is an instance of the
MovieClip class.) Same goes fo ryour globalVolume variable: globalVolume
is an instance name for your Sound instance.

> btnMute.onRelease = function() {

Oops! Your button's instance name is Mute, but you're assigning a
function to the Button.onRelease event of an object whose instance name is
btnMute. Either change this function assignment to ...

Mute.onRelease = function() {

... or rename your button instance to btnMute.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


gorcoAuthor
Participating Frequently
May 19, 2006
Hi again,

Sorry, but I tried modifying code but the sound in my movie doesn't get turned off.

I only have one button, in which I named the instance "Mute". Is this the way the code should be written?:

var volumeOn:Boolean = true;
var globalVolume:Sound = new Sound();
btnMute.onRelease = function() {
if (volumeOn) {
globalVolume.setVolume(0);
} else {
globalVolume.setVolume(100);
}
volumeOn = !volumeOn;
}
Inspiring
May 18, 2006
gorco,

>> Sorry to be thick David,

Ha! No worries. I don't think you're being thick.

>> Could you explain what you mean by removing it from
>> the button and putting it in the frame?

Back in the days of Flash 5, if you wanted to code up a button or movie
clip, you had to select the button, open the Actions panel, and add your
instructions in an on() event handler (or onClipEvent() for certain movie
clip events). Since Flash MX (aka Flash 6), it's possible to address
buttons and movie clips via their instance names.

>> If it's not attached to the button, how will the code
>> implement when the user clicks the button?

The code calls the object by name (by instance name) and tells it what
to do.

btnInstanceName.onRelease = function() {
// do something
}

vs.

on(release) {
// do something
}

> Maybe the problem is that I have not created an Instance
> name for my Mute button?

That's got to be it. If you think about it, when the code is directly
attached to the button, the code obviously knows which button it is
instructing. If the code is attached to a frame, there needs to be some way
to address the relevant button -- namely, an instance name.

> So instead of selecting the button and attaching script to
> it, should I be creating an Instance name for the Mute
> button, and then the script will know it relates to the button?

Exactly. The code goes into a keyframe, then.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


gorcoAuthor
Participating Frequently
May 18, 2006
Maybe the problem is that I have not created an Instance name for my Mute button? So instead of selecting the button and attaching script to it, should I be creating an Instance name for the Mute button, and then the script will know it relates to the button?
gorcoAuthor
Participating Frequently
May 18, 2006
Sorry to be thick David,
Could you explain what you mean by removing it from the button and putting it in the frame? If it's not attached to the button, how will the code implement when the user clicks the button?
Inspiring
May 18, 2006
gorco,

> I still have a problem (perhaps because I don't understand
> the syntax);

The syntax is fine; you're putting your code in the wrong place.

> THIS WAS THE ERROR MESSAGE..
> Scene=Scene 1, Layer=Mute Sound, Frame=1: Line 1:
> Statement must appear within on handler

This error means the statement must appear within an on() event handler.
The only time statements need to appear within on() handlers is when they're
directly attached to an object (such as a button).

Remove your code from the button and put it in a frame.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


gorcoAuthor
Participating Frequently
May 18, 2006
Hi again,

I still have a problem (perhaps because I don't understand the syntax);
The botton I created on the main timeline is called "Mute". I'm trying to turn the volume to zero so that all tracks of sound a no longer audible. I tried the following code, in various forms and get this type of syntax error message:

THIS IS WHAT I TRIED (MY BUTTON NAME IS "MUTE")
var globalVolume:Sound;
btnMute.onRelease;{
globalVolume.setVolume(0);
}
btnMute.onRelease = function() {
globalVolume.setVolume(100);
}
THIS WAS THE ERROR MESSAGE..
Scene=Scene 1, Layer=Mute Sound, Frame=1: Line 1: Statement must appear within on handler
var globalVolume:Sound;
Scene=Scene 1, Layer=Mute Sound, Frame=1: Line 2: Statement must appear within on handler
btnMute.onRelease;{
Scene=Scene 1, Layer=Mute Sound, Frame=1: Line 5: Statement must appear within on handler
btnMute.onRelease = function() {
I ALSO TRIED.....
var globalVolume:Sound = new Sound();
btnSoundOff.onRelease = function() {
globalVolume.setVolume(0);
}
btnSoundOn.onRelease = function() {
globalVolume.setVolume(100);
}
May 16, 2006
Interestingly... I provided a link to your blog yesterday, David, in another one of gorco's threads: http://groups.google.com/group/macromedia.flash.actionscript/browse_frm/thread/e52d09f6cedbf7f6/82cc6b822877642a?lnk=st&rnum=1#82cc6b822877642a