Custom Cursors Demo in FP 10.2


You will need Flash Player 10.2 to view this!

Since FP10.2 is out, I thought I’d make a custom cursors demo. It relies on two outside libraries, MinimalComps and as3Gif. The project files are here! The demo demonstrates a static cursor, an animated one, and one you can draw in the program.


Vodpod videos no longer available.

If this doesn’t work, or is scaled funny for you, go here.

Here’s a little sample of the source, illustrating some of the new things you can do. This is the code for using the user-drawn image as the cursor:

public function useCursor():void
{
	//Create bitmap data for cursor
	var data:BitmapData = new BitmapData(32, 32, true, 0);
	
	//Create scaling matrix
	var m:Matrix = new Matrix();
	m.scale(.25, .25);
			
	//Draw canvas to bitmapdata, only 128x128 rectangle (which will be scaled to 32x32, the max cursor size)
	data.draw(canvas, m, null, null, new Rectangle(0, 0, 128, 128));
			
	//Set cursor options
	var mouseData:MouseCursorData = new MouseCursorData();
	//Notice that the data property is a vector of BitmapData. new <BitmapData>[data] is the quick way to create a vector.
	mouseData.data = new <BitmapData>[data];
	//Set the hot spot to the user inputed location
	mouseData.hotSpot = new Point(parseInt(xPos.text), parseInt(yPos.text));
			
	//Register and use cursor
	Mouse.registerCursor("created", mouseData);
	Mouse.cursor = "created";
}

Note that the BitmapDatas in the BitmapData Vector must be 32×32 or smaller.

Additional resources:
FP10.2 Announcement
More Cursor Info here.

Advertisements

6 responses to “Custom Cursors Demo in FP 10.2

  1. After smacking my head against a wall on this one for ages I just wanted to add – the cursors MUST be 32×32 in size. Every other size I tried crashes Flash Player at run-time claiming that the registerCursor() call has been given invalid data.

    • Thanks for the comment – to clarify, they must be 32 x 32 or smaller. I just tested with a 20 x 20, and that also worked well. Also added a missing <BitmapData> in the code, somehow it had gotten removed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s