简体   繁体   English

AS3-MouseWheelDown侦听器

[英]AS3 - MouseWheelDown listener

Is there any way to detect if the mouse wheel is held down? 有什么方法可以检测是否按住了鼠标滚轮? I need to pan my scene while the middle button or mouse wheel is pushed down (I thought holding the mouse wheel down was the same as middle mouse button, but it aint working). 我需要在按下中间按钮或鼠标滚轮的同时平移场景(我认为按住鼠标滚轮与鼠标中键相同,但是它不能正常工作)。

Thanks! 谢谢!

Though I never used it there's MIDDLE_CLICK event which works only in AIR apps. 尽管我从未使用过它,但MIDDLE_CLICK事件仅在AIR应用程序中有效。 Does your app run in browser or on desktop? 您的应用是在浏览器中运行还是在桌面上运行?

Also, just my 2 cents, it's so damn inconvenient to use scrollwheel button in an application. 而且,仅我的2美分,在应用程序中使用滚轮按钮真是太不方便了。 Each time I am forced to do that in some 3D modelling tool I want to smash my monitor. 每次我被迫在某些3D建模工具中执行此操作时,我都希望粉碎显示器。 I'd use just shift/alt/ctrl + mouse1/mouse2. 我只会使用shift / alt / ctrl + mouse1 / mouse2。

This is possible with as3, came across this so here it is: 使用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);

How about trying out this: 如何尝试一下:

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

this detects the left mouse... if you substitute the argument (1) with (2) you get the right mouse button so... 这会检测到鼠标左键...如果将参数(1)替换为(2),则会得到鼠标右键,因此...

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

and if you put in a (4) you get the middle mouse or often the wheel button... 如果您输入(4),您会得到鼠标中键或滚轮按钮...

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

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

PS: I would suggest not using the middle mouse or wheel button because not everyone has a middle mouse button. PS:我建议不要使用鼠标中键或滚轮按钮,因为不是每个人都有鼠标中键。 So if you still want the usability of a middle mouse button, please adjust your functions accordingly so a person without a middle mouse button can still pan the canvas. 因此,如果您仍然希望使用鼠标中键,请相应地调整功能,以便没有鼠标中键的人仍可以平移画布。

EDIT: 编辑:

Ok, I made a booboo! 好吧,我做了个嘘声! Didn't catch it had to be for AS 3.0. 没发现它一定是针对AS 3.0。 The support for the middle/right mouse button click is no longer available in AS 3.0. 在AS 3.0中不再支持单击鼠标中键/右键。 Atleast not directly. 不直接联系Atleast。

One way to do it is using JS to detect the mouse button that's being pressed and then giving that variable as a string into Flash. 一种方法是使用JS检测被按下的鼠标按钮,然后将该变量作为字符串提供给Flash。

How to detect a mouse click in JS: http://www.quirksmode.org/js/events_properties.html 如何在JS中检测鼠标单击: http : //www.quirksmode.org/js/events_properties.html

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

Or you can do it directly through a hack in AS 3.0: (limited browser & OS support) http://flashpunk.net/forums/index.php?topic=2549.0 或者,您也可以直接通过AS 3.0中的黑客操作来做到这一点:(受限的浏览器和操作系统支持) http://flashpunk.net/forums/index.php?topic=2549.0

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM