AS3 - MouseWheelDown监听器

时间:2012-02-21 09:29:56

标签: actionscript-3 flex events

有没有办法检测鼠标滚轮是否被按下?当中间按钮或鼠标滚轮被按下时我需要平移我的场景(我认为按住鼠标滚轮与鼠标中键相同,但它不起作用)。

谢谢!

3 个答案:

答案 0 :(得分:1)

虽然我从未使用它,但MIDDLE_CLICK事件仅适用于AIR应用程序。您的应用在浏览器或桌面上运行吗?

另外,仅仅是我的2美分,在应用程序中使用滚轮按钮真是太不方便了。每次我被迫在一些3D建模工具中这样做时,我想要粉碎我的显示器。我只使用shift / alt / ctrl + mouse1 / mouse2。

答案 1 :(得分:0)

尝试这个怎么样:

this.onEnterFrame = function() {
if (ASnative(800, 2)(1)) { 
trace ("You have pressed or depressed the left mouse button");
}
}

这会检测到鼠标左键......如果用(2)替换参数(1),你会得到鼠标右键......

this.onEnterFrame = function() {
if (ASnative(800, 2)(2)) { 
trace("You have pressed or depressed the right mouse button");
}
}

如果你放入(4)你得到中间鼠标或经常是滚轮按钮......

this.onEnterFrame = function() { 
if (ASnative(800, 2)(4)) {
trace("You have pressed or depressed the middle mouse or wheel button");
}
}

来源:http://www.actionscript.org/forums/showthread.php3?t=68209

PS:我建议不要使用鼠标中键或滚轮按钮,因为不是每个人都有鼠标中键。因此,如果你仍然想要鼠标中键的可用性,请相应地调整你的功能,这样没有鼠标中键的人仍然可以平移画布。

编辑:

好的,我做了一个booboo!没有抓到它必须是AS 3.0。 AS 3.0中不再支持鼠标中键/右键单击。 至少不是直接的。

一种方法是使用JS检测正在按下的鼠标按钮,然后将该变量作为字符串提供给Flash。

如何在JS中检测鼠标点击: http://www.quirksmode.org/js/events_properties.html

如何将此变量放入Flash:(ExternalInterface) http://learn.adobe.com/wiki/display/Flex/External+Interface

或者您可以通过AS 3.0中的黑客直接执行此操作:(有限的浏览器和操作系统支持) http://flashpunk.net/forums/index.php?topic=2549.0

DEMO:http://www.shinyhappypixels.com/punk-forums/clicky-hook/

答案 2 :(得分:0)

这可以通过as3来实现,所以这里是:

import flash.events.MouseEvent;

function handleMouseWheel(event:MouseEvent):void {

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

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

}

}

stage.addEventListener(MouseEvent.MOUSE_WHEEL, handleMouseWheel);