BlitzMouse right-click capture example
sergej wrote a comment to my BlitzMouse post saying that if you right-clicked the custom pointer gets lost until the page is refreshed. Here is some simple code to work around this.
In your main SWF make sure you import ContextMenu and ContextMenuEvent. Then add 2 new global vars:
[as]
private var rightClickContext:ContextMenu;
private var contextOpen:Boolean;
[/as]
and within your init (or constructor) add this:
[as]
rightClickContext = new ContextMenu();
this.contextMenu = rightClickContext;
rightClickContext.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenuOpen, false, 0, true);
[/as]
“this” is a Sprite in this case, but any valid display object (that has access to the contextMenu) will do. The “contextMenuOpen” function is literally just the following:
[as]
private function contextMenuOpen(event:ContextMenuEvent):void
{
contextOpen = true;
}
[/as]
and finally, in your main game loop, just check the state of this var and reset accordingly:
[as]
if (contextOpen && mouse.isDown)
{
mouse.hide();
}
[/as]
When the context menu is opened (by a right-click on Windows) it fires the ContextMenuEvent.MENU_SELECT event, which we capture and set a boolean for accordingly. While the menu is open we can do nothing about the standard mouse pointer, but in our main loop we can listen out for a mouse click (mouse.isDown) and then hide the pointer again accordingly.
I’ve not tested this on a Mac (where you can command-click to get the context menu up) so if anyone reading can do so, please let me know if it works.
The SWF below should allow you access to the context menu, but upon clicking the SWF again the custom pointer should return (assuming you click within the limit zone!)
[swfobj src=”http://sandbox.photonstorm.com/blitzMouseTest2.swf” width=”550″ height=”400″]
Posted on September 16th 2008 at 2:28 pm by Rich.
View more posts in PixelBlitz. Follow responses via the RSS 2.0 feed.
Make yourself heard
Hire Us
All about Photon Storm and our
HTML5 game development services
Recent Posts
OurGames
Filter our Content
- ActionScript3
- Art
- Cool Links
- Demoscene
- Flash Game Dev Tips
- Game Development
- Gaming
- Geek Shopping
- HTML5
- In the Media
- Phaser
- Phaser 3
- Projects
Brain Food