6
votes

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
}
1
Are you sure you've attached the RIGHT_MOUSE_UP listener to the Stage as that's very important.xLite
Can you post a snippet please?Chris
Added an edit showing how my code works. The event listeners are indeed added to the stage.Godfather

1 Answers

2
votes

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.