Return to Snippet

Revision: 32808
at October 2, 2010 09:23 by bshantz

Initial Code
package  {
	import flash.display.Sprite;
	import flash.display.Loader;
	import flash.ui.Mouse;
	public class CustomCursor extends Sprite {
		private var request:URLRequest;
		private var cursorLoader:Loader;
		/*	When you create a custom cursor, pass in the URL of the cursor you want to use	*/
		public function CustomCursor(url:String='crosshair_image.png') {
		public function setCursor(url:String):void
			/*	Load our image from the url path	*/
			request = new URLRequest(url);
			cursorLoader = new Loader();
			/*	Listen for when the content of the loader is finished loading	*/
			cursorLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, cursorLoaded);
		private function cursorLoaded(event:Event):void
			/*	The width and height of the new cursor	*/
			var w:Number =;
			var h:Number =;
			/*	Center the image on the mouse	*/
			cursorLoader.x = -w/2;
			cursorLoader.y = -h/2;
			/*	Hide the default cursor	*/
			/*	Add the cursor graphic to the stage	*/
			/*	startDrag keeps the object the same x,y as the mouse cursor	*/

Initial URL

Initial Description
This is a class I made for using custom cursors without having to import them into an FLA.  Just pass in the URL of the cursor image and you're good to go.

Initial Title
Custom Cursor from image URL in AS3

Initial Tags

Initial Language
ActionScript 3