tags:

views:

423

answers:

3

How can I skin, or otherwise change, the default cursor (white arrow) displayed in a Flex application?

A: 

Yes, this is possible. You'll need to leverage mx.managers.CursorManager.

There's no way to replace the cursor graphic, but you achieve this by adding a new cursor to the manager with a high priority:

 CursorManager.setCursor(myCursor, CursorManagerPriority.HIGH);

In the above example, myCursor can be a JPEG, GIF, PNG, or SVG image, a Sprite object, or a SWF file. Additionally, setCursor accepts two additional parameters, xOffset:Number = 0, yOffset:Number = 0, which you can use to, well, offset the image from the actual pointer position, if you need to.

Re: Your comment:

I believe you're correct. There's no way I know of to override a components hover cursor other than some event foo. Keep in mind that it is the most recently added cursor with the highest priority (to the `CursorMangager, of course) that gets displayed.

jason
I did that but when placing the cursor inside, for instance, a TextInput field Flex displays the default text selection cursor along with the custom cursor that was added...Is there a way to simply skin the default cursor? Or is it necessary to have some Event listening trickery to get this to work as intended?
Tiago Pereira
A: 

If you wat to change the cursur you need to check the mouse when it is currently over the TextField sub-object of the Flex TextInput control:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" mouseMove="application1_mouseMoveHandler(event)">

    <fx:Script>
     <![CDATA[

      protected function application1_mouseMoveHandler(event:MouseEvent):void
      {
       if(event.target is TextField)
       {
        if(TextField(event.target).type == TextFieldType.INPUT)
        {
         Mouse.hide();
        }
       }
       else
       {
        Mouse.show();
       }
      }

     ]]>
    </fx:Script>

    <mx:TextInput width="300" />
</s:Application>

This is simply making it go away, but you could use the opportunity to make the cursor anything you want by replacing Mouse.hide() with the CursorManager methods described in the other comments. I don't really consider this event "trickery" and overriding the PlayerGlobals.swc class is always going to be more difficult than the open Flex SDK stuff.

Joel Hooks
I was about to implement that... trickery like I said. I only used that word because i feel it should exist a simpler way to achieve this, like skinning the cursor. Thanks!
Tiago Pereira