Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 如何反转音量滑块的音量数学?_Flash_Actionscript 3_Math_Audio_Volume - Fatal编程技术网

Flash 如何反转音量滑块的音量数学?

Flash 如何反转音量滑块的音量数学?,flash,actionscript-3,math,audio,volume,Flash,Actionscript 3,Math,Audio,Volume,我正在制作一个视频播放器,但音量滑块部分有点卡住了。这是一个YouTube风格的垂直滑块,这意味着如果滑块位于顶部位置,音量应为100%,如果滑块拖动到底部位置,声音应为0。目前它正在做与我想要的相反的事情:( 向下拖动滑块会使声音更大,而向上拖动会降低声音 下面是我处理音量滑块的代码 // Sound Controller Settings ······························ soundController = new SoundController();

我正在制作一个视频播放器,但音量滑块部分有点卡住了。这是一个YouTube风格的垂直滑块,这意味着如果滑块位于顶部位置,音量应为100%,如果滑块拖动到底部位置,声音应为0。目前它正在做与我想要的相反的事情:(

向下拖动滑块会使声音更大,而向上拖动会降低声音

下面是我处理音量滑块的代码

// 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);
    }
[轨迹]当我一直拖动到顶部时:

soundController.mouseY = 6
soundContrGray.height  = 6
userVolume             = 0
[痕迹]当我一路向下拖动时:

soundController.mouseY = 56
soundContrGray.height  = 56
userVolume             = 30
我相信这就是问题所在:

userVolume = Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);
(-4)是一个偏移值,因此当您一直拖动它以将其关闭时,它是0而不是4。
我需要以某种方式反转它,所以上面的跟踪将交换…向下将使userVolume=4,向上将使其为30


提前感谢所有看过这张照片的人!:)

因为当你想要100%的音量时,你会得到0,当你想要0%的音量时,你会得到30。。。试试这个

setVolume(100 - (userVolume * 100 / 30));

Substitude 0 in equation:
setVolume(100 - (0 * 100 / 30)) --> simplifies to
setVolume(100);

Substitute 30 in equation:
setVolume(100 - (30 * 100 / 30)); --> simplifies to
setVolume(100 - (3000 / 30)); --> simplifies to
setVolume(100 - 100); --> simplifies to
setVolume(0);

我一定错过了什么,因为事情不可能这么简单,不是吗

userVolume = 30-Math.round(((soundContrGray.y * soundContrGray.height) / 10) - 4);

从概念上讲,您要做的是让声音越低越高
soundContrGray
。因此,您需要一个最大值(或者在本例中是一个最大高度)来与当前值进行比较。我认为
30
是音量滑块背景的高度。我将使用
bg
作为背景高度

userVolume = (soundContrGray.height / bg.heigth);
userVolume = Math.round((1 - userVolume) * 100);

这将给出一个相对音量设置,与实际元素的高度或它们在屏幕上的位置无关。

userVolume=Math.round(100*(1-soundContrGray.height/(soundContrGray.y-4))
Doh就是这样:)谢谢!嗯,我想我太专注于()内部发生的事情了,我从来没有想到会这样做……绿色音量指示器上覆盖着一个灰色的矩形,起初我试图控制绿色矩形,但得到了奇怪的结果。因此,我决定只在绿色上方设置灰色矩形的动画,因为这是我控制的矩形移动的方向。(更正了跟踪语句)我喜欢你说的,我不需要硬编码太多的数字。。。