Rant: Don’t call Mouse.hide() each frame!

Here is a little rant!

If you’re using a custom cursor, don’t freaking call Mouse.hide() each frame!

It’s really not neccesary! It’s using some CPU power that you probably need somewhere else, and it has some treribble side effects – at least if the user is using firefox (haven’t tested on other browsers). What happens is, when I move away from the SWF, my mouse disappears! Only if I move it around, can I see it… flickering!

Stop it! You only need to call it ONCE – and that is when you start your preloader!


So what about when a user right-clicks?” you say! Well handle that rightclick, and call Mouse.hide() !


It’s too hard, there’s no build in event for closing right click menus!

Well then today is your lucky day! Here is working code that does just that for you:


public static function initRightClickMouseHider ( rootRef:InteractiveObject ) :void
	if (!rootRef.contextMenu )
		var contextMenu:ContextMenu = new ContextMenu ( ) ;
		rootRef.contextMenu = contextMenu;
	rootRef.contextMenu.addEventListener ( ContextMenuEvent.MENU_SELECT, menuWasSelected ) ;
private static function menuWasSelected(e:ContextMenuEvent):void 
	e.contextMenuOwner.root.stage.addEventListener ( MouseEvent.MOUSE_OVER, onMouseOver ) ;
private static function onMouseOver(e:MouseEvent):void 
	(e.target as InteractiveObject) .root.stage.removeEventListener ( MouseEvent.MOUSE_OVER, onMouseOver ) ;
	Mouse.hide ( ) ;

Posted on January 13th, 2011
Filed under ActionScript 3, Flash, Rant, User Interface, Util |

Leave a Reply