I am creating a video player and am a bit stuck in part of the volume slider. This is a YouTube-style vertical slider, that is, if the slider is in the upper position, the volume should be 100%, and if the slider is dragged to the lower position, the sound should be 0. Currently, it does the opposite of what I want: (
Dragging the slider down will make the sound louder, and dragging it will reduce it.
Here is my code below regarding the volume slider.
soundController = new SoundController();
soundContrColor = soundController.colorChip;
soundContrGray = soundController.grayCover;
soundContrGray.visible = false;
soundController.visible = true;
soundController.buttonMode = true;
soundController.soundSlider.addEventListener(MouseEvent.MOUSE_DOWN, sliderDown);
public function sliderDown(event:MouseEvent):void
{
soundController.soundSlider.startDrag(false, dragBounds);
soundController.soundSlider.addEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
soundController.soundSlider.addEventListener(MouseEvent.MOUSE_UP, sliderUp);
soundContrGray.visible = true;
}
public function sliderMove(event:MouseEvent):void
{
soundContrGray.height = soundController.soundSlider.y;
userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);
setVolume(userVolume);
trace("soundController.mouseY = "+soundController.soundSlider.y);
trace("soundContrColor.height = "+Math.round(soundContrGray.height));
trace("userVolume = "+userVolume+"\r");
event.updateAfterEvent();
}
public function sliderUp(event:MouseEvent):void
{
lastVolPoint = soundContrGray.height;
setVolume(userVolume);
event.updateAfterEvent();
soundController.soundSlider.stopDrag();
soundController.soundSlider.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMove);
soundController.soundSlider.removeEventListener(MouseEvent.MOUSE_UP, sliderUp);
}
[TRACES] when I drag to the end:
soundController.mouseY = 6
soundContrGray.height = 6
userVolume = 0
[TRACES] when I completely drag down:
soundController.mouseY = 56
soundContrGray.height = 56
userVolume = 30
I believe this is the problem:
userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);
(- 4) - , , , , 0, 4.
- , ... userVolume = 4, 30.
, !:)