| Package | flash.ui |
| Class | public final class Mouse |
| Inheritance | Mouse Object |
| Language Version: | ActionScript 3.0 |
| Runtime Versions: | AIR 1.0 Flash Player 9 |
See also
Public Properties
| Property | Defined By | ||
|---|---|---|---|
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | |
| cursor : String [static]
Sets the mouse cursor. | Mouse | ||
![]() | prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | |
Public Methods
| Method | Defined By | ||
|---|---|---|---|
![]() |
Indicates whether an object has a specified property defined. | Object | |
[static]
Hides the pointer. | Mouse | ||
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
[static]
Displays the pointer. | Mouse | ||
![]() |
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | |
![]() |
Returns the string representation of the specified object. | Object | |
![]() |
Returns the primitive value of the specified object. | Object | |
Property Detail
cursor | property |
cursor:String| Language Version: | ActionScript 3.0 |
| Runtime Versions: | Flash Player 10, AIR 1.5 |
Sets the mouse cursor.
The default value is flash.ui.MouseCursor.AUTO.
To set values for this property, use the following string values:
| String value | Description |
|---|---|
flash.ui.MouseCursor.AUTO | Mouse cursor will change automatically based on the object under the mouse. |
flash.ui.MouseCursor.ARROW | Mouse cursor will be an arrow. |
flash.ui.MouseCursor.BUTTON | Mouse cursor will be a button clicking hand. |
flash.ui.MouseCursor.HAND | Mouse cursor will be a dragging hand. |
flash.ui.MouseCursor.IBEAM | Mouse cursor will be an I-beam. |
Implementation
public static function get cursor():String public static function set cursor(value:String):voidThrows
ArgumentError — If set to any value which is not a member of flash.ui.MouseCursor.
|
See also
Method Detail
hide | () | method |
public static function hide():void| Language Version: | ActionScript 3.0 |
| Runtime Versions: | AIR 1.0 Flash Player 9 |
Hides the pointer. The pointer is visible by default.
Note: You need to call Mouse.hide() only once, regardless of
the number of previous calls to Mouse.show().
See also
show | () | method |
public static function show():void| Language Version: | ActionScript 3.0 |
| Runtime Versions: | AIR 1.0 Flash Player 9 |
Displays the pointer. The pointer is visible by default.
Note: You need to call Mouse.show() only once, regardless of
the number of previous calls to Mouse.hide().
See also
Examples ( How to use this example )
MouseExample.as
The following example uses the MouseExample, SimpleButton,
ButtonDisplayState, and CustomCursor classes to place a simple button on the Stage. The button
has a custom pointer and the button changes when clicked. This is accomplished with the following steps:
- Declare the following instance properties:
cursorof type CustomCursor,childof type CustomButton, andgutterof type uint. - Assign
childto a new CustomButton instance, set its x and y coordinates to 10 pixels each, and then add the instance to the display list. The CustomButton class overrides thedownState,upState,overState, andhitTestStateproperties in SimpleButton. Each of these properties instantiates a ButtonDisplayState object, which draws a different square, depending on the state of thechildinstance. - The
childinstance is then used to add aMOUSE_OVERevent listener andmouseOverHandler()listener method, along with aMOUSE_OUTevent listener and associatedmouseOutHandler()method. - The event listeners work as follows:
mouseOverHandler: Hides the "normal" pointer and adds aMOUSE_MOVElistener, which processes the mouse moves usingmouseMoveHandler(), described below.mouseOutHandler: When the mouse moves outside the custom button, the "normal" pointer is shown, theMOUSE_MOVEevent listener is removed, and the custom cursor's visibility is set tofalse.mouseMoveHandler: Moves the custom cursor around wherever the pointer is moved and sets the custom cursor's visibility totrue.
- Back in the
MouseExampleconstructor, the cursor property is assigned to a new CustomCursor object and then added to the display list usingaddChild(). The CustomCursor class draws a small nearly black square in place of the "normal" pointer whenever the mouse is overchild. - A fourth event listener of type
MOUSE_LEAVEis added, with the associatedmouseLeaveHandler()method. In this method (called if the mouse leaves the Stage),mouseOutHandler()is passed a newmouseMovelistener object, which essentially removes the pointer so it is not left on the Stage.
package {
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.ui.Mouse;
import flash.events.*;
public class MouseExample extends Sprite {
private var cursor:CustomCursor;
private var child:CustomButton;
private var gutter:uint = 10;
public function MouseExample() {
child = new CustomButton();
child.x = gutter;
child.y = gutter;
addChild(child);
child.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
child.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
cursor = new CustomCursor();
addChild(cursor);
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeaveHandler);
}
private function mouseOverHandler(event:MouseEvent):void {
trace("mouseOverHandler");
Mouse.hide();
child.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
}
private function mouseOutHandler(event:MouseEvent):void {
trace("mouseOutHandler");
Mouse.show();
child.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
cursor.visible = false;
}
private function mouseMoveHandler(event:MouseEvent):void {
trace("mouseMoveHandler");
cursor.x = event.localX;
cursor.y = event.localY;
event.updateAfterEvent();
cursor.visible = true;
}
private function mouseLeaveHandler(event:Event):void {
trace("mouseLeaveHandler");
mouseOutHandler(new MouseEvent(MouseEvent.MOUSE_MOVE));
}
}
}
import flash.display.Shape;
import flash.display.SimpleButton;
class CustomButton extends SimpleButton {
var upColor:uint = 0xFFCC00;
var overColor:uint = 0xCCFF00;
var downColor:uint = 0x00CCFF;
var size:uint = 80;
public function CustomButton() {
downState = new ButtonDisplayState(downColor, size+10);
overState = new ButtonDisplayState(overColor, size);
upState = new ButtonDisplayState(upColor, size);
hitTestState = new ButtonDisplayState(upColor, size);
}
}
class ButtonDisplayState extends Shape {
var bgColor:uint;
var size:uint;
public function ButtonDisplayState(bgColor:uint, size:uint) {
this.bgColor = bgColor;
this.size = size;
draw();
}
private function draw():void {
graphics.clear();
graphics.beginFill(bgColor);
graphics.drawRect(0, 0, size, size);
graphics.endFill();
}
}
class CustomCursor extends Shape {
var bgColor:uint = 0x333333;
var size:uint = 10;
public function CustomCursor() {
visible = false;
draw();
}
private function draw():void {
graphics.clear();
graphics.beginFill(bgColor);
graphics.drawRect(0, 0, size, size);
graphics.endFill();
}
}
Fri Mar 19 2010, 02:45 AM -07:00

Hide Inherited Public Properties
Show Inherited Public Properties