16 Replies Latest reply on May 20, 2006 4:13 PM by NSurveyor

    Sound in Movie

    gorco
      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.
        • 1. Re: Sound in Movie
          Level 7
          gorco,

          > 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).

          Why is this problem? What ActionScript did you use to toggle off your
          sound?

          > 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).

          You should be able to add a layer above all other layers in your FLA.

          > Does the button have to be added to the All Movie clip so I
          > can select it to then attache the ON click script?

          I'm afraid I dont' understand what you mean by the phrase "All Movie
          clip," but you should only have to add your button once (or once per Scene,
          if your FLA has Scenes).

          > If so, how do I add it. Thanks in advance.

          This is one of the biggest problems with buying a premade template,
          unfortunately. People buy them, but don't know how to customize them,
          because they don't know how to use Flash. Since you didn't make this
          template yourself, you face something of a challenge in even describing the
          FLA.

          Your main timeline will have a number of layers in it. If you create a
          button and put it in a layer that appears above all the others, your button
          should always show.

          Have you tried that? What ActionScript are you using?


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


          • 2. Re: Sound in Movie
            gorco Level 1
            David said:

            "Your main timeline will have a number of layers in it. If you create a
            button and put it in a layer that appears above all the others, your button
            should always show.

            Have you tried that? What ActionScript are you using?"

            Hi David,

            Yes I did that, but it only turns off the layer of sound I can see in my main timeliine. It doesn't turn off the 5 layers of sound in the "All" movie clip. I can only see 7 layers in my main timeline. When I open the "All" movie clip, there are about 50 layers in the timeline. So to Mute, I first selected my Mute button that's on the workspace and then selected the Actionsript to ON Release, Turn off all Sounds. This works for the layer in the main timeline, but does not turn off the sounds running in the "all" movie clip.
            • 3. Re: Sound in Movie
              Level 7
              gorco,

              > Yes I did that, but it only turns off the layer of sound I
              > can see in my main timeliine.

              I still don't know what ActionScript you used.

              > So to Mute, I first selected my Mute button that's on the
              > workspace and then selected the Actionsript to ON Release,
              > Turn off all Sounds. This works for the layer in the main
              > timeline, but does not turn off the sounds running in the "all"
              > movie clip.

              I'm not sure if you're using a Behavior. Maybe that's it. The easiest
              way I know of to turn off the sound for the whole SWF is to set the global
              volume on and off. Read details here ...

              http://www.quip.net/blog/2006/flash/how-to-toggle-sound-globally

              Some interesting alternatives in the Comments section, too.


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


              • 4. Re: Sound in Movie
                gorco Level 1
                Thank you David! I went to your blog and read the great explanation. I will try setting the volume to zero tonight. By the way, I was using the actionscript
                stopAllSounds().

                Instead I'll try:

                btnSoundOff.onRelease = function() {
                globalVolume.setVolume(0);
                }
                btnSoundOn.onRelease = function() {
                globalVolume.setVolume(100);
                }

                Thanks again!
                • 5. Re: Sound in Movie
                  Level 7
                  gorco,

                  > Thank you David! I went to your blog and read the great
                  > explanation. I will try setting the volume to zero tonight.

                  Thanks! It comes up often enough in these forums, I figured I'd blog on
                  it.

                  > By the way, I was using the actionscript stopAllSounds().

                  Gotcha. Okay, well, that's it, then. That stops all sounds currently
                  playing, but doesn't keep new ones from occurring.


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


                  • 6. Re: Sound in Movie
                    RonnieFizz
                    hum interesting
                    • 7. Re: Sound in Movie
                      NSurveyor Level 2
                      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/e52d09f6ced bf7f6/82cc6b822877642a?lnk=st&rnum=1#82cc6b822877642a
                      • 8. Re: Sound in Movie
                        gorco Level 1
                        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);
                        }
                        • 9. Re: Sound in Movie
                          Level 7
                          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."


                          • 10. Re: Sound in Movie
                            gorco Level 1
                            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?
                            • 11. Re: Sound in Movie
                              gorco Level 1
                              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?
                              • 12. Re: Sound in Movie
                                Level 7
                                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."


                                • 13. Re: Sound in Movie
                                  gorco Level 1
                                  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;
                                  }
                                  • 14. Re: Sound in Movie
                                    Level 7
                                    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."


                                    • 15. Sound in Movie
                                      gorco Level 1
                                      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.....
                                      • 16. Re: Sound in Movie
                                        NSurveyor Level 2
                                        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;
                                        };