2 Replies Latest reply on Apr 5, 2007 8:13 AM by soodonimus

    Volume Slider

    soodonimus
      Hello, I have created a volume slider with a button that starts in the center. When I drag the button left, the volume increases. When I drag right the volume decreases. How do I change the volume so that dragging left will decrease the sound and dragging right will increase the sound?

      onClipEvent (load) {
      top = _y;
      bottom = _y;
      center = _x;
      left = center - 40;
      right = center + 40;

      }
      onClipEvent (enterFrame) {
      if (dragging == true) {
      this._parent.mySound.setVolume(100-((_x-center)*2.5));
      }
      }
        • 1. Re: Volume Slider
          Level 7

          "soodonimus" <webforumsuser@macromedia.com> wrote in message
          news:ev1cft$e84$1@forums.macromedia.com...
          > Hello, I have created a volume slider with a button that starts in the
          > center.
          > When I drag the button left, the volume increases. When I drag right the
          > volume
          > decreases. How do I change the volume so that dragging left will decrease
          > the
          > sound and dragging right will increase the sound?
          >
          > onClipEvent (load) {
          > top = _y;
          > bottom = _y;
          > center = _x;
          > left = center - 40;
          > right = center + 40;
          >
          > }
          > onClipEvent (enterFrame) {
          > if (dragging == true) {
          > this._parent.mySound.setVolume(100-((_x-center)*2.5));
          > }
          > }
          >

          If I understand, you start the button in the center, which I assume is 50%
          volume?


          If you are setting the registration point to the upper left then...
          left = _x;
          right = _x + _width;

          If it is the center then...
          left = _x - _width / 2;
          right _x + _width / 2;

          Then...
          var gotoLocation = 100 * (_right - _x ) / _width
          this._parent.mySound.setVolume(gotoLocation);

          NOTE: Not tested...



          • 2. Re: Volume Slider
            soodonimus Level 1
            Thank you! Yes, I want the button to start in the center at 50% volume. I see that the variable controls the volume direction. I want the volume to decrease when I slide left and increase when I slide right, so here is the final code:

            onClipEvent (load) {
            top = _y;
            bottom = _y;
            center = _x;
            left = center - 40;
            right = center + 40;

            }
            onClipEvent (enterFrame) {
            if (dragging == true) {
            var gotoLocation = 100*(left-_x)/40;
            this._parent.mySound.setVolume(gotoLocation);
            }
            }