Changing the cursor in a Flex application using the CursorManager class

by Peter deHaan on September 10, 2007

in CursorManager

The following code shows how you can toggle the “busy” cursor in Flex using the static setBusyCursor() and removeBusyCursor() methods in the CursorManager class, as well as using your own custom cursors by calling the static setCursor() and removeCursor() methods.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/10/changing-the-cursor-in-a-flex-application-using-the-cursormanager-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            import mx.managers.CursorManager;

            [Bindable]
            [Embed(source="assets/bug.png")]
            private var BugIcon:Class;

            [Bindable]
            [Embed(source="assets/bug_delete.png")]
            private var BugDeleteIcon:Class;

            private var cursorID:int;
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Button label="setBusyCursor()"
                click="CursorManager.setBusyCursor();" />
        <mx:Button label="removeBusyCursor()"
                click="CursorManager.removeBusyCursor();" />
    </mx:ApplicationControlBar>

    <mx:Button label="setCursor()"
            width="100"
            height="100"
            rollOver="cursorID = CursorManager.setCursor(BugIcon);"
            rollOut="CursorManager.removeCursor(cursorID);" />

</mx:Application>

View source is enabled in the following example.

{ 11 comments… read them below or add one }

1 Manju September 14, 2007 at 4:40 am

cool………..!

Reply

2 bLb November 18, 2007 at 10:33 pm

As usual very useful! Thanks!

Reply

3 Anz November 29, 2007 at 12:02 am

Hi,

I set the cursor of a textinput using CursorManager

The new cursor is showing but it also showing the default text cursor on roll over of the text box.

How can I solve it?

Thanks
Anz
http://www.flickrmailer.com

Reply

4 Wajiw November 24, 2009 at 1:04 pm

To get rid of the default text cursor I added selectable = false; to the text element. Not sure if you need that or not, but that worked for me.

Reply

5 Divya February 4, 2008 at 1:54 pm

I was using the setBusyCursor() and removeBusyCursor() methods in my application,until I had two tabs in my app which loaded once my Application initialized.Both these tabs make remote method calls,and display the busy cursor until the results come back.This resulted in the busy cursor getting converted into a normal cursor before the data come back.Here is a blog post related to this and how we could use a progress bar instead and pointers on ProgressBar:
http://flex-j2ee.blogspot.com/2008/01/flex-progressbar-versus-cursormanager.html

Reply

6 sammy September 20, 2008 at 11:04 am

I am trying to create a custom set of cursors for my app tha dont have to be turned on, can this code be edited so it is automatically switched on without a button needed to be pressed?

Reply

7 Naj February 8, 2009 at 11:02 pm

Very useful tip ,

Thanks

Can we set tooptip for busy cursor instead of loading image ?

Reply

8 molaro March 16, 2009 at 7:43 am

I have an application where when the user clicks a button I removeAllChildren() from an HBOX, and then run a loop through my data to add new children to the same HBOX (I’m paginating the children). The first line of my function sets the busy cursor and the last line removes it as it takes a second or so to swap the children. However, when I click the button my cursor just disappears instead of showing the busy cursor. Then when the process is done the regular cursor returns. Why does my BusyCursor disappear when removing / adding children? Is there a way to prevent that from happening? Is this a bug or performance issue?

Reply

9 Migs April 15, 2009 at 7:33 am

I have the same problem Anz has.

The new cursor and the text cursor overlay each other. Does anybody know how to fix this problem?

Reply

10 David Zamora January 4, 2010 at 1:44 pm

Hi,
I am changing the cursor successfully, but I need to disable the cursor click event while the information that I am retrieving is displayed?
Can I do this? How can I do it?

Reply

11 Anonymous January 12, 2010 at 9:12 am

Gracias, este artículo es de mucha utilidad!!!!!!

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree

Previous post:

Next post: