Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash right click acting differently than left click

I've just updated to flash player 11.2 which allows for listening to MouseEvent.RIGHT_MOUSE_UP and MouseEvent.RIGHT_MOUSE_DOWN.

I am having a problem where these events don't act the same as their MOUSE_UP / MOUSE_DOWN counterparts. Specifically, the MOUSE_UP event is launched no matter where the mouse is. This allows for dragging outside the flash window and still having a complete down -> up event loop whenever a user clicks in the flash player.

However, this does not seem to be the case for RIGHT_MOUSE_UP / DOWN. When I right click inside the player and release outside of the player, I don't get a RIGHT_MOUSE_UP event meaning it is possible to receive multiple RIGHT_MOUSE_DOWN events without receiving an UP event.

Is there a known workaround to this or is there an option I must set?

Edit :

Here is a code example :

stage.addEventListener(MouseEvent.MOUSE_UP,         onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_DOWN,       onMouseDown);
stage.addeventListener(MouseEvent.RIGHT_MOUSE_UP,   onRightMouseUp);
stage.addeventListener(MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown);

//...
//all callback function follow a similar format as :
private function onMouseUp(e : MouseEvent) : void
{
    leftClick_ = false;//signaling that leftClick is not pressed
}
like image 823
Godfather Avatar asked Apr 29 '12 08:04

Godfather


1 Answers

you could listen for when the mouse leaves the stage, which could act as a proxy to a RIGHT_CLICK_UP event.

package 
{
    //Imports
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.MouseEvent;

    //Class
    [SWF(width="640", height="480", frameRate="60", backgroundColor="0x555555")]
    public class RightClickTest extends Sprite
    {
        //Constructor
        public function RightClickTest()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        //Initialize
        private function init(event:Event):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);

            stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, mouseRightClickEventHandler);
            stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, mouseRightClickEventHandler);
            stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveEventHandler);
        }

        //Mouse Right Click Event Handler
        private function mouseRightClickEventHandler(event:MouseEvent):void
        {
            switch (event.type)
            {
                case MouseEvent.RIGHT_MOUSE_DOWN:   trace("Right Mouse Down");
                                                    break;

                case MouseEvent.RIGHT_MOUSE_UP:     trace("Right Mouse Up");
            }
        }

        //Mouse Leave Event Handler
        private function mouseLeaveEventHandler(event:Event):void
        {
            trace("Mouse Leave");
        }
    }
}

however, if you are trying to avoid allowing the user to display multiple right-click context menus (or something similar), you could implement a simple check in your code to first hide a visible right-click context menu before displaying the new one.

like image 133
Chunky Chunk Avatar answered Oct 16 '22 12:10

Chunky Chunk