Tutorials

February 26, 2009

Quick Tips: AS3 Hiding/Showing the Mouse

More articles by »
Written by: Par
Tags: , , , ,
quicktipimage

Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit

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.

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.

Similar Posts:


Share on TwitterShare on TumblrSubmit to StumbleUponSave on DeliciousDigg ThisSubmit to reddit


About the Author

Par
Hey! Don't be surprised, I'm a flash developer. While Flash is definitely one of my favorite languages to develop in, most of all I just like making games. If you want to see the games I've developed so far head over to my website, DigitallyBold, in the link below. If you want to know more about what I'm working on now and in the future be sure to follow me on twitter.




6 Comments


  1. Anup

    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

    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

    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

    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


  5. This doesn’t seem to be working for me in Firefox 5. As a matter of fact, the button mouse hand icon doesn’t even appear. It works in Safari. Any tips?


  6. AP

    Hi,

    Somehow the example doesn’t work on my Mac. If I click, the cursor disappears, but it doesn’t come back. If I try it on another Mac, it does work. Any ideas on this?

    Thanks,

    AP



Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">


Advertisement