2 Replies Latest reply on Jan 15, 2007 12:45 AM by lajettee

    sound volume

    lajettee
      Hi currently porting from lingo to flash and need a simple solution to this problem. I have 2 movieclps on stage and wish one to function as an "up" volume control and the other to work as a "down" control. Incrementally. I've written this code. I can get the "up" control to work fine, but he "down" volume won't work. Any ideas or tutorials gratefully received.

      quote:


      //variable set to 0
      up_vol = 0;


      sound_up_mc.onPress = function() {

      //on mouse press increment the value of vol by 10
      up_vol = up_vol + 10

      //set the volume value of the sound to the value contained in vol.
      my_sound.setVolume(up_vol);


      }

      //set a variable for down volume.

      down_vol = 0

      sound_down_mc.onPress = function() {

      //plug the down_vol value into the setvolume parameter

      down_vol = down_vol - 10
      my_sound.setVolume(down_vol);

      }




      many thanks

      julie
      *
        • 1. Re: sound volume
          NSurveyor Level 2
          Well, it would make more sense to have simply one volume variable. The up button will increase this value, whilst the down button will decrease it. Also, instead of using code like "x = x+10", we can use the 'addition assignment operator' which does the same thing: x+=10. With that said, could have something like:


          vol = 0;
          sound_up_mc.onPress = function() {
          vol+=10;
          my_sound.setVolume(vol);
          }

          sound_down_mc.onPress = function() {
          vol-=10;
          my_sound.setVolume(vol);
          }

          But let's consider when you hit the down volume button when the volume is already at 0, it will become negative. The same idea applies to the up volume button when the volume reaches 100, except it will exceed the maximum volume. To handle that, we can use an if statement, to bring the volume within the proper range:

          //Initial volume
          vol = 0;
          my_sound.setVolume(vol);
          //Increse volume button
          sound_up_mc.onPress = function() {
          vol+=10;
          if(vol > 100){
          vol = 100;
          }
          my_sound.setVolume(vol);
          }
          //Decrease volume button
          sound_down_mc.onPress = function() {
          vol-=10;
          if(vol < 0){
          vol = 0;
          }
          my_sound.setVolume(vol);
          }
          • 2. Re: sound volume
            lajettee Level 1
            Thanks very much for your suggestions.

            julie

            X