AS Gamer Limelight Tutorial

spotlight
An Even Better AS3 OOP Flash Custom Cursor In the last tutorial we created a custom cursor, in this tutorial we'll address some issue...

AS Gamer Spotlight Tutorials

Quick Tips: AS3 Hiding/Showing the Mouse



Trying to figure out how to hide and show the mouse in as3? It’s simple. Here’s the deal.

Imports Required:
imports allow us to use other classes within our application. Simply add it inside your package if within a class.

  • flash.ui.Mouse;

Now when you want your Mouse to disappear just call Mouse.hide();

To reappear the mouse simply call Mouse.show();

Example:
Make the mouse disappear and reappear with each click.

Make a mouse disappear and reappear after clicks

Document Class:

package {
 
	import flash.ui.Mouse;
	import flash.display.MovieClip;
	import flash.events.*;
 
	public class MouseToggle extends MovieClip
	{
		private var mouseToggle:Boolean = true;
 
		public function MouseToggle()
		{
			stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);
		}
 
		function mouseDownHandler(e:MouseEvent) {
			if (mouseToggle)
				Mouse.hide();
			else
				Mouse.show();
 
			mouseToggle = !mouseToggle;
		}
 
	}
 
}

I know that was quick and easy… but hey! that’s a Quick Tip.

Tags: , , , ,


Where to Go Next?


February 26th, 2009 | Quick Tips |

4 Responses to “Quick Tips: AS3 Hiding/Showing the Mouse”

  1. Anup says:

    Dear Sir

    I have tried to work out your code but its not working at my end I want your help is it possible to discuss with you regarding this example.

    help me to solve this issue.

    waiting for your reply

    Anup

  2. Par says:

    Are you using it as the document class? Please sign up for a forum account and post your issue there and I or someone will do our best to assist you.

  3. jacobs says:

    mmm…
    Could you explain the ‘imports’ and why are you extending to ‘MovieClip’?

    As i’m new in both POO and AS3 i’m confused.

    Here is what i understand:
    importing ui.Mouse for Mouse.show and Mouse.hide methods
    importing events.* for MouseEvent.MOUSE_EVENT event

    But how about importing and extending ‘MovieClip’ (im really confused at this point, are the same ‘MovieClip’s?, what they are used to?)

  4. Par says:

    There are other articles on this website that explain that. Search for them.
    http://asgamer.com/2009/flash-game-design-basics-adding-library-objects-to-stage-with-as3

Leave a Reply

Sponsors & Links

Build Flash Online advertisement advertisement advertisement