3 Replies Latest reply on Jul 20, 2007 6:26 AM by woolyboy

    Volume Slider Errors

    woolyboy
      Hi all,

      I'm quite confused, and I'm hoping you can help me out.

      I'm trying to create a slider bar that raises and lowers the volume of only the vocals. I have two sound objects, one for the instrumental and one for the vocals. However, I just can't get the slider bar to control sound obect 2 (the vocals). I'll show you what I have, and hopefully you can point me in the right direction.

      First of all, I have a slider bar in a movie clip called "slider". Inside this movie clip, I use the following ActionScript:


      this.perc=0 ;
      handle.onPress=function(){
      this.startDrag(true,0,0,rail._width,0);
      this.onEnterFrame=function(){
      perc=Math.round(this._x*100/rail._width) ;
      }
      }
      handle.onRelease=stopDrag;
      handle.onReleaseOutside=stopDrag;

      _parent._parent.soundObject2.setVolume( perc );



      I have placed the movie clip inside a movie clip called "mc_control". The slider moves fine, but that's not the problem.

      The "control_mc" movie clip is placed inside another movie clip entitled "mc_scenes_all", where I created the variables for the two sound objects.

      Unfortunately, the volume slider doesn't work -- nothing happens to the sound when I move it.

      Do you know what I'm doing wrong?

      Thanks so much for your time.
        • 1. Re: Volume Slider Errors
          Rothrock Level 5
          I'm a bit confused, is the problem that the slider is controlling both sounds and you only want it to control one? Or is the problem that it isn't controlling any sounds?

          It is odd that you got the percent calculation inside the onEnterFrame but not the setVolume. You need both inside the onEnterFrame because you want to calculate the percentage repeatedly, but it does no good if you don't set it each time you calculate a new one.

          Make sure that in your stopDrag (which is kind of a bad name for a function since it is almost the same as the MovieClip.stopDrag() method) you do the following:

          delete handle.onEnterFrame;

          It is a good habit to get into that you always make sure to delete your onEnterFrames when they aren't needed anymore. In this case one little calculation and setVolume won't waste too many resources, but in the future…

          So let's get that working and then we can work on the controlling sounds independently if you run into that!
          • 2. Re: Volume Slider Errors
            woolyboy Level 1
            Thanks for the reply.

            Actually, the slider works fine inside the parent movie clip "mc_control". I can slide it, but it doesn't control ANYTHING. I want it to control only the vocals volume only (which is SoundObject2). SoundObject1 is the instrumental track.

            One good thing is that I have confirmed that SoundObject 1 and SoundObject2 can be controlled independently. So, at the very least, I know that part of it is set up correctly.

            The problem is how to get the "perc" variable out of the "slider" movie clip, and pass it back two levels to the "mc_scenes_all" movie clip. I thought I would be doing it correctly by using:

            _parent._parent.soundObject2.setVolume( perc );

            However, it does not work.

            Any advice?
            • 3. Re: Volume Slider Errors
              woolyboy Level 1
              Figured it out.

              ORIGINAL CODE:

              this.perc=0 ;
              handle.onPress=function(){
              this.startDrag(true,0,0,rail._width,0);
              this.onEnterFrame=function(){
              perc=Math.round(this._x*100/rail._width) ;
              }
              }
              handle.onRelease=stopDrag;
              handle.onReleaseOutside=stopDrag;

              _parent._parent.soundObject2.setVolume( perc );


              FIXED CODE:

              this.perc=0 ;
              handle.onPress=function(){
              this.startDrag(true,0,0,rail._width,0);
              this.onEnterFrame=function(){
              perc=Math.round(this._x*100/rail._width) ;
              _parent._parent.soundObject2.setVolume( perc );
              }
              }
              handle.onRelease=stopDrag;
              handle.onReleaseOutside=stopDrag;

              //The bold statement had to be moved INSIDE the handle statement -- which makes sense. Garrrr, that took a really long time.

              Thanks for your help. I really appreciate it.