[AS3] RIGHT_MOUSE_UP

9 posts

Flag Post

From some reason I cant get a function to fire after the right mouse button is up.

// Removes The Right Click Screen
stage.addEventListener(MouseEvent.RIGHT_CLICK, function(e:Event){});
// Right Mouse Up Function That's Not Working
stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, rightMouseIsUp);
// Diffrent Function Added To A Sprite That Happens on RightMouseDown and works just fine
mapHolder.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, startMapDrag)	
private function startMapDrag(e:MouseEvent):void
{
	trace("Works") // This does output
	currentlyDraggingMap = true
	mapHoldDragStartX = stage.mouseX + mapHolder.x
	mapHoldDragStartY = stage.mouseY + mapHolder.y
	mapHolder.addEventListener(MouseEvent.MOUSE_MOVE, mouseMapMovement)
}	
private function rightMouseIsUp(e:MouseEvent):void
{
	trace("Why Wont This Trace") // Doesn't Output
	if(currentlyDraggingMap == true)
	{
		mapHolder.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMapMovement)
		currentlyDraggingMap = false
	}
}

Is there some other way I have to go about this. I have the right mouse down happening on the object but when it is moved it is possible for the mouse to not be released over that same object so I need the RIGHT_MOUSE_UP to fire whenever and wherever the right-mouse is released on the stage.
 
Flag Post

Do you have a background image? MouseEvents don’t register on an empty stage.

 
Flag Post

I actually do have a background image but I did not know that mouseEvents don’t register on an empty stage. The image was not added through code however it was just placed on the stage. I tried adding from the library instead and this had no change on the result.

Any other ideas?

 
Flag Post

Starfire: I’m pretty sure they do, as long as you add the listener to stage rather than root. I tried it with an empty stage, and all three right-mouse-related events fired just fine. (Ok, so there were one or two empty sprites on the stage, but neither of them contained a background.)

Evan: I was going to suggest adding the listeners to different objects, but I doubt that would tell us anything useful. Instead, try creating a new project and adding this code:

stage.addEventListener(MouseEvent.RIGHT_CLICK, onMouseEvent);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, onMouseEvent);
stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, onMouseEvent);
function onMouseEvent(e:MouseEvent):void {
	trace(e.type);
}

Which of the three events get traced?

 
Flag Post

Player if I do that exactly 1 trace of “rightMouseDown” outputs.

If I comment out the others to find which statement it is, the statement that works is unsurprisingly


stage.addEventListener(MouseEvent.RIGHT_MOUSE_DOWN, onMouseEvent);

Much like the only one that works in my other document. Very strange that it’s working this way.

 
Flag Post

Oh well I just discovered that if I launch the swf from the folder and not as a test movie in flash it works fine… What the heck could cause it to work fine when launched as a swf as oppose to tested in flash and what do you think I could to do fix this?

I also found this reply to a thread http://stackoverflow.com/questions/12175515/as3-mouseevent-right-mouse-up-doesn’t-work but using older versions doesn’t change it in flash player I’v tried from 10.3-11.7

Hrmmmmmm.

 
Flag Post

maybe its simple…

// Right Mouse Up Function That's Not Working
stage.addEventListener(MouseEvent.RIGHT_MOUSE_UP, rightMouseIsUp);

//needs to be
mapHolder.addEventListener(MouseEvent.RIGHT_MOUSE_UP, rightMouseIsUp);

I had problems long ago with this same issue, with mouse events. It is because the way events go through the display list; they go up through the display list hierarchy, though I am not sure if they hit stage – that is, if stage counts. I quit messing with listeners / refs to stage anyways except for the main controller class, but thats a tangent. One thing to remember is that they dont go sideways through display-list hierarchy’s. I think what happened here, to cause your problem, is that by adding the listener to stage, stage never recieves the event because the mouse event is hitting the mapHolder display object, not the stage on which everything is on-top of.

Another caveat is to make sure that the mapHolder has the stage focus / or that there isnt another display object on top of it, that isnt part of its display list hierarchy

 
Flag Post

The point of it being added to the stage is that because of what this function does. The RIGHT_MOUSE_DOWN can move the mapHolder image off the screen so the RIGHT_MOUSE_UP function needs to fire when the right mouse button is released anywhere on the file. Additionally I have tested it when there is no other item on the frame blocking the mouse from hitting the direct stage and it also doesn’t explain how what I currently have works when launched in the swf from the folder but not when I test movie in flash. I think the only explanation is that something is messed up with flash player somewhere.

 
Flag Post

Lucidius: It’s safe to add mouse listeners to the stage. In fact, it’s more reliable than adding them anywhere else.

Also, mouse events set the focus; you don’t need to set the focus beforehand. You’re thinking of key events, and even then you wouldn’t need to worry about focus as long as you added the event listeners to the stage.

Finally, it’s untrue that everything is “on-top of” the stage. The stage is a DisplayObjectContainer, and it contains all other display objects. Thanks to bubbling, any event dispatched to any display object in the game will also be dispatched on the stage. (Assuming you don’t call stopPropagation() to cancel it.)

evan999333: Yeah, launching from the Flash IDE can give weird results. Don’t worry about it too much; the weirdness only happens there, and no one will see those particular bugs when you upload the game.