as3 mouse wheel reverse

断了今生、忘了曾经 提交于 2019-12-25 01:58:04

问题


Hey i built custom scroll box. When i scroll up on this box scrolling element is going down and when i scroll down - scrolling element is going up ;). I whant to reverse that mechanism. how can i do it ? Below my code for mouse

import flash.events.MouseEvent;

function handleMouseWheel(event:MouseEvent):void {
    if ((event.delta > 0 && box_mc.y < 171) || (event.delta < 0 && box_mc.y > 135)) 
    {

        box_mc.y = box_mc.y + (event.delta * 3);
        sb.thumb.y = sb.thumb.y + (event.delta * 13);

        trace(box_mc.y);
        trace(event.delta);

    }
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);

回答1:


All you need to do is invert the delta value (or the direction in which you scroll):

if ((event.delta > 0 && box_mc.y < 171) || (event.delta < 0 && box_mc.y > 135)) 
{

    box_mc.y = box_mc.y + (-event.delta * 3);
    sb.thumb.y = sb.thumb.y + (-event.delta * 13);

    trace(box_mc.y);
    trace(event.delta);

}

Notice all I have done is put a minus symbol in front of the event.delta value.



来源:https://stackoverflow.com/questions/14876389/as3-mouse-wheel-reverse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!