Please look at the following quick and dirty example :) You would need to replace the images I am embedding with yours...
Hope it helps..
-abdul
1) CursorExample.mxml
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml " creationComplete="onAppInit ()">
<mx:Script>
<![CDATA[
import com.abdulqabiz.utils.*;
[Embed(source="images/cursor1.jpg")]
[Bindable]
public var tool:Class;
[Embed(source="images/cursor2.jpg")]
[Bindable]
public var tool2:Class;
private var cursorPool:CursorPool;
function onAppInit ():void
{
cursorPool = CursorPool.getInstance ();
cursorPool.register (hbox1, new CursorAttributes (tool));
cursorPool.register (hbox2, new CursorAttributes (tool2));
}
]]>
</mx:Script>
<mx:HBox id="hbox1" width="200" height="200" backgroundColor="0xFF0000" />
<mx:HBox id="hbox2" width="200" height="200" backgroundColor="0x00FF00"/>
<mx:HBox id="hbox3" width="200" height="200" />
</mx:Application>
2) Class: com.abdulqabiz.utils.CursorPool
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);
}
}
}
3) Class: com.abdulqabiz.utils.CursorAttributes
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;
}
}
}
On 9/6/06, Paul Hastings <
[EMAIL PROTECTED]> wrote:
would something like the followng be considered "good practice" for
managing cursors (ie changing mouse cursor based on some user
selection & using mouseOver events to turn on the chosen cursor &
mouseOut events to return the mouse cursor to the system cursor)?
thanks.
private function setCursor():void {
if (toolCursor !=null) {
CursorManager.removeCursor(cursorID);
cursorID = CursorManager.setCursor(toolCursor);
}
}
private function removeCursor():void {
CursorManager.removeCursor(cursorID);
}
.
.
.
<mx:Image source="{theMap}" mouseOver="setCursor();"
mouseOut="removeCursor();"/>
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
![]()
SPONSORED LINKS
Software development tool Software development Software development services Home design software Software development company
YAHOO! GROUPS LINKS
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
__,_._,___
- Re: [flexcoders] mouse cursor management Abdul Qabiz
- [flexcoders] Re: mouse cursor management coldfusionpaul
- [flexcoders] Re: mouse cursor management coldfusionpaul
Reply via email to

