Hi Stackers, I'm building a video player and am kinda stuck at the volume slider part. It's a YouTube style vertical slider, meaning if the slider is in the top position volume should be 100% and if the slider is dragged to the bottom position sound should be 0. Currently it's doing the opposite of what I want :(
Dragging the slider down will make the sound louder, while dragging up lowers it.
Here is my code below dealing with the volume slider.
// Sound Controller Settings ······························
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);
// SoundController Button Mouse Events ························
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);
//userVolume = soundContrGray.height;
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 all the way to the top:
soundController.mouseY = 6
soundContrGray.height = 6
userVolume = 0
[TRACES] when I drag all the way down:
soundController.mouseY = 56
soundContrGray.height = 56
userVolume = 30
I believe this is where the problem lies:
userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);
The (-4) is an offset value so when you drag it all the way to turn it off, it's 0 and not 4.
I need to reverse this somehow, so the traces above will swap... going down will make userVolume = 4 and going up will make it 30.
Thanks in advance for anyone that takes a look at this one! :)