ActionScript® 3.0 Reference for the Adobe® Flash® Platform
Home  |  Show Packages and Classes List |  Packages  |  Classes  |  What's New  |  Index  |  Appendixes
flash.ui 

MouseCursorData  - AS3

Packageflash.ui
Classpublic final class MouseCursorData
InheritanceMouseCursorData Inheritance 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

Related API Elements



Public Properties
 PropertyDefined By
 Inheritedconstructor : 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
 MethodDefined By
  
Creates a MouseCursorData object.
MouseCursorData
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
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

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.)

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;
        }
    }
    
}