Skip to content

Instantly share code, notes, and snippets.

@abdul
Created March 10, 2015 06:38
Show Gist options
  • Save abdul/ad844420392babadc7eb to your computer and use it in GitHub Desktop.
Save abdul/ad844420392babadc7eb to your computer and use it in GitHub Desktop.
package com.abdulqabiz.utils
{
public class CursorAttributes extends Object
{
public var cursorType:Class = null;
public var priority:int = 2;
public var xOffset:Number = 0;
public var yOffset:Number = 0;
public function CursorAttributes (cursorType:Class,
priority:int=2, xOffset:Number = 0, yOffset:Number = 0)
{
this.cursorType = cursorType;
this.priority = priority;
this.xOffset = xOffset;
this.yOffset = yOffset;
}
}
}
package com.abdulqabiz.utils
{
import mx.managers.CursorManager;
import mx.core.UIComponent;
import flash.events.*;
public class CursorPool extends Object
{
static private var instance:CursorPool = null;
static public function getInstance ():CursorPool
{
if (!instance)
{
instance = new CursorPool ();
}
return instance;
}
private var registry:Object;
private var cursorID:int;
public function CursorPool ()
{
registry = new Object ();
}
public function register (component:UIComponent, cursorAttributes:CursorAttributes):void
{
if (component)
{
registry[String (component)] = cursorAttributes;
component.addEventListener ("mouseOver", handleMouseOver);
component.addEventListener ("mouseOut", handleMouseOut);
}
}
public function unregister (component:UIComponent):void
{
component.removeEventListener ("mouseOver", handleMouseOver);
component.removeEventListener ("mouseOut", handleMouseOut);
delete registry[String (component)];
}
private function handleMouseOver (event:MouseEvent):void
{
var component:UIComponent = UIComponent (event.target);
var ca:CursorAttributes = registry[String (component)];
if (cursorID)
{
CursorManager.removeCursor (cursorID);
}
cursorID = CursorManager.setCursor (ca.cursorType, ca.priority, ca.xOffset, ca.yOffset);
}
private function handleMouseOut (event:MouseEvent):void
{
CursorManager.removeCursor (cursorID);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment