views:

87

answers:

3

How to work with specific mouse buttons such as xbutton1 and xbuton2?

+1  A: 

You can only access the left (or primary) mouse button in Flash. You can create custom context menus though that are accessed via right click.

Just saw that you have selected the AIR tag, so I guess you are targetting AIR. Then you'll be able to access all mouse buttons. See flash.events.MouseEvent for details, on which events are available.

To add an event listener for MouseEvents to an DisplayObject simply do something like this:

displayObject.addEventListener( MouseEvent:MOUSE_DOWN, myMouseDownHandler );

Where myMouseDownHandler is an event handler function like this:

function myMouseDownHandler ( event:MouseEvent )
{
    // do something
}

edit

As said in a comment, it's not possible for Flash (or actually any other program) to determine if an additional button on the mouse is pressed. The mouse driver is responsible for mapping those button clicks to special commands (such as opening a program etc), and you could even do fancy stuff like overwriting the right mouse click to something else and putting it on a completely different button (in which way that other button would report as "right click" in programs).

So no, you can't access additional mouse buttons in Flash.

poke
MouseEvent:MOUSE_DOWN works only for mouse's left button.And as i can see, there is no solution for my problem in flash.events.MouseEvent(
Serji
FYI MouseEvent.MOUSE_WHEEL can also be used within the Flash Player (SWF), for what it's worth.
liquidleaf
@Serji: I just used `MOUSE_DOWN` as an example; there are other button related mouse events available in air (for example `RIGHT_MOUSE_DOWN`, `MIDDLE_CLICK` etc). @liquidleaf: I wouldn't call the mouse wheel a button, but rather a scroll :P
poke
A: 

If you programming Air, there are mousedown, rightMouseDown, and middleMouseDown events. If you're not programming air, you are indeed right, and there is only the one mouse down event.

mezmo
So, there is no way to control button 4 and button5? http://www.egg-tech.com/blog/images/mouse%20buttons.jpg And yes, i'm programming air.
Serji
Ah, that's what you want. No that's not possible. A mouse only has three native buttons (left, mid, right). The other buttons are special buttons which function can be assigned by the driver, but do not map to normal mouse buttons.
poke
Windows uses this buttons to navigate in explorer, and some browsers too. damn air(
Serji
No, your mouse driver maps those buttons to functions that are able to navigate in programs.
poke
A: 

Hmm, i've found interesting post here Same problem, and it seems that solution was found!

I used an AS2 swf and ASNative to register the mouse events and sent them to my AS3 swf over a LocalConnection

Can anybody say how to use this?

Serji
And here is example: http://web.archive.org/web/20040604053600/www.sukimashita.com/content/code/flash/2003/03/onmousedownex/onmousedownex.html
Serji