Created
March 10, 2015 06:38
-
-
Save abdul/ad844420392babadc7eb to your computer and use it in GitHub Desktop.
Flex 2 CursorPool - http://www.abdulqabiz.com/blog/archives/2006/09/07/flex-2-cursorpool-for-cursor-management/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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