flash.ui

# MouseCursorData - AS3

Package | flash.ui
Class | public final class MouseCursorData
Inheritance | MouseCursorData Object

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10.2, AIR 2.6

The MouseCursorData class lets you define the appearance of a "native" mouse cursor.

To display the cursor, use the `Mouse.registerCursor()` function. To return control of the cursor image to the operating system, call `Mouse.unregisterCursor()`. Call `Mouse.supportsNativeCursor` to test whether native cursors are supported on the current computer.

The maximum cursor size is 32x32 pixels.Transparency is supported on most operating systems.

A native mouse cursor is implemented directly through the operating system cursor mechanism and is a more efficient means for displaying a custom cursor image than using a display object. You can animate the cursor by supplying more than one image in the `data` property and setting the frame rate.

The cursor is only displayed within the bounds of the stage. Outside the stage, control of the cursor image returns to the operating system

View the examples

Learn more

AIR Cookbook: Native Mouse cursor for Flash Player 10.2+

Related API Elements

flash.ui.Mouse.cursor

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object
|  | data : Vector.<BitmapData> A Vector of BitmapData objects containing the cursor image or images. | MouseCursorData
|  | frameRate : Number The frame rate for animating the cursor. | MouseCursorData
|  | hotSpot : Point The hot spot of the cursor in pixels. | MouseCursorData

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | MouseCursorData() Creates a MouseCursorData object. | MouseCursorData
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Property Detail

### data

property

`data:Vector.<BitmapData>`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10.2, AIR 2.6

A Vector of BitmapData objects containing the cursor image or images.

Supply more than one image and set the `framerate` property to animate the cursor.

The maximum cursor size is 32x32 pixels.

Implementation
`public function get data():Vector.<BitmapData>`
`public function set data(value:Vector.<BitmapData>):void`

### frameRate

property

`frameRate:Number`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10.2, AIR 2.6

The frame rate for animating the cursor.

Suppy more than one image in the `data` property and set the frame rate to a value greater than 0 to animate the cursor. The cursor frame rate may differ from the current SWF frame rate.

Implementation
`public function get frameRate():Number`
`public function set frameRate(value:Number):void`

### hotSpot

property

`hotSpot:Point`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10.2, AIR 2.6

The hot spot of the cursor in pixels.

The hotspot is the point on the cursor under which mouse clicks are registered. By default, the hot spot is the upper-left corner (0,0).

Implementation
`public function get hotSpot():Point`
`public function set hotSpot(value:Point):void`
Constructor Detail

### MouseCursorData

()
Constructor

`public function MouseCursorData()`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 10.2, AIR 2.6

Creates a MouseCursorData object.

To display the cursor, call the `Mouse.registerCursor()` function.

Related API Elements

flash.ui.Mouse.registerCursor()
Examples How to use this example
MouseCursorDataExample.as
The following example creates and displays a spinning arrow for the mouse cursor.

The example uses the drawing commands available through the Graphics class to create eight, rotated images of an arrow. These images are pushed into a vector and assigned to the `data` property of the MouseCursorData object. (Note that you can also use prerendered bitmap images for your cursors.)

Copy

    package  {

        import flash.display.Sprite;
        import flash.display.Shape;
        import flash.display.BitmapData;
        import flash.display.GraphicsPath;
        import flash.ui.MouseCursorData;
        import flash.ui.Mouse;
        import flash.geom.Matrix;

        public class MouseCursorDataExample extends Sprite {
            //Graphics path data for an arrow
            private var cursorPoints:Vector.<Number> = new <Number>[0,8, 16,8, 16,0, 24,12, 16,24, 16,16, 0,16, 0,8];
            private var cursorDrawCommands:Vector.<int> = new <int>[1,2,2,2,2,2,2,2];

            public function MouseCursorDataExample() {
                var mouseCursorData:MouseCursorData = new MouseCursorData();
                mouseCursorData.data = makeCursorImages();
                mouseCursorData.frameRate = 1;

                Mouse.registerCursor( "spinningArrow", mouseCursorData );
                Mouse.cursor = "spinningArrow";
            }

            //Returns a Vector containing 8 cursor images
            private function makeCursorImages():Vector.<BitmapData>
            {
                var cursorData:Vector.<BitmapData> = new Vector.<BitmapData>();

                var cursorShape:Shape = new Shape();
                cursorShape.graphics.beginFill( 0xff5555, .75 );
                cursorShape.graphics.lineStyle( 1 );
                cursorShape.graphics.drawPath( cursorDrawCommands, cursorPoints );
                cursorShape.graphics.endFill();
                var transformer:Matrix = new Matrix();

                //Rotate and draw the arrow shape to a BitmapData object for each of 8 frames
                for( var i:int = 0; i < 8; i++ )
                {
                    var cursorFrame:BitmapData = new BitmapData( 32, 32, true, 0 );
                    cursorFrame.draw( cursorShape, transformer );
                    cursorData.push( cursorFrame );

                    transformer.translate(-15,-15);
                    transformer.rotate( 0.785398163 );
                    transformer.translate(15,15);
                }
                return cursorData;
            }
        }

    }

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00