Using useHandCursor in Flex

 

While working on a recent Flex project I found a code sample that someone created because they were having trouble getting the useHandCursor to work. It was pretty obvious what they were trying to do, take a look:

<mx:Canvas width="176" height="87">
<mx:Link height="100%" width="100%" />
<mx:Image width="100%" height="100%"
source="@Embed(''images/logo.swf'')"
mouseDown="doThis()" />
</mx:Canvas>

They obviously wanted to call an event handler when someone clicked on the image, but because they couldn”t get useHandCursor to work, they used an alternative method, albeit not all that pretty.

The solution is rather simple though. Just add a mouseOver event to the component and set it to the following:

mouseOver="event.target.onRelease=null;
event.target.useHandCursor=true;"

Works pretty much anywhere.

UPDATED For Flex 2:

You may have noticed that the above does not work in Flex 2. This process has been replaced. It is now done through a set of properties that are inherited from the Sprite class.

useHandCursor="true"
buttonMode="true

Add these properties to your component and you”re all set. Now, that was easy!

 

Leave a Comment

Rob Rusher :.: Building Engaging Experiences for the Browser, Desktop, Mobile and TV