Flex Blog

Search:
  • Home
  • Examples
    • Thumb

      Flex Examples

      Check out our Flex Examples!

    • Thumb

      Flash Builder Examples

      Check out our Flash Builder Examples!

    • Thumb

      AIR Examples

      Check out our AIR Examples!

    • Thumb

      Flex Mobile Examples

      Check out our Flex Mobile Examples!

    Adobe® Flex, Adobe® Flash Builder and Adobe® AIR are registered trademarks of Adobe Systems.
  • Components
    • Thumb

      WP Flex Contact Form

      Check out our WP Flex Contact Form!

    • Thumb

      Flash CountDown Plugin

      Check out our Flash CountDown Plugin!

    This is an overview of all our Flash/Flex based Components.
  • Jobs
  • Flex Books
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
  • iOS
Browse > Home / Examples / Set custom cursor using the CursorManager

Set custom cursor using the CursorManager

18 November 2009

Line Break

Author: Roelof (13 Articles) - Author Website

Roelof is a SAP Consultant specialized in Front-End development. In his spare free time he is either developing on the web, playing basketball, watching soccer or traveling. He is also the co-owner of Flex-Blog.com.


After my previous post about setting the busy cursor, I decided to write a next post about custom Cursors. In our example we use an Image as a Cursor source, but you can also use a SWF file.

The CursorManager allows you to use your custom cursors in a very simple way. The most important method is the setCursor() method, which can be used as follows:

1
CursorManager.setCursor(myCursor);


View Source is enabled for this example (Right Mouse -> View Source).

Scroll down for the full source code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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" width="400" height="160" viewSourceURL="srcview/index.html">
   
    <fx:Script>
        <![CDATA[
            import flash.events.*;
           
            import mx.controls.Button;
            import mx.managers.CursorManager;
           
            //If you want you can also insert an SWF file as cursor!            
            [Bindable]
Embed("cursors/cursor1.png")]
            private var myCursor:Class;
           
            private var myCursorID:int;
           
           
            private function toggleButtonHandler(event:MouseEvent):void
            {
                var toggleButton:Button = event.target as Button;
                if ( toggleButton.selected )
                {
                    myCursorID = CursorManager.setCursor(myCursor);
                }
                else
                {
                    CursorManager.removeCursor( myCursorID );    
                }
            }
        ]]>
    </fx:Script>
   
    <mx:Panel
        paddingBottom="10" paddingTop="10" paddingLeft="10" paddingRight="10"
        horizontalAlign="center" verticalAlign="middle"
        title="Custom Cursor Example"
        >        
       
        <mx:Button label="Toggle" toggle="true"
            click="toggleButtonHandler(event);"
            />
       
        <mx:Text text="Click the button to display or hide the custom cursor."/>
    </mx:Panel>
</s:Application>

Related posts:

  1. Set busy Cursor using the CursorManager
  2. Looping over an ArrayCollection with Cursor Example
  3. Flex Custom Event Example

Written by Roelof · Filed Under Examples 

Was this post useful to you?

Please rate this post, follow us @ twitter, or link to this page from your website!

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 1.60 out of 5)
Loading ... Loading ...

f14624de6677e89f70639c7fb0052234delicious

Comments

2 Responses to “Set custom cursor using the CursorManager”

  1. Sunit on April 16th, 2010 7:32 am

    Hi Roelof,

    Thanx for this article. There 2 issues i find in this.

    One is the custom cursor is having some offset in both x and y direction from the actual cursor. Is there a way to correct this offset?

    And other thing is, when you take the mouse over a text field(in your case text which is below the button “Click the button to…”) , there are 2 cursors visible , custom as well as a system cursor. Is there any way to hide the system cursor?

    Regards,
    Sunit.

  2. Roelof on April 16th, 2010 10:44 am

    Hi Sunit,

    Issue 1 can be solved using the offset parameters of the method setCursor. Code will look like this:

    myCursorID = CursorManager.setCursor(myCursor, 2, -5, -5);

    I can see Issue 2 in this example, but can not reproduce this in the new Flash Builder 4. So it might have been a bug.

    Regards,
    Roelof

Get Adobe Flash player

  • +1?

  • Support Flex Blog!

  • $ 13 raised
    • 2012/01/13 8:22 PM Russell Brown donated $ 3.00
    • 2011/10/31 4:43 PM Steve Dakin donated $ 5.00
    • 2011/05/11 3:37 PM Roelof Albers donated $ 5.00
  • Stay in touch!

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • CursorManager
    • DataGrid
    • Dynamic
    • Effects
    • File
    • FileStream
    • Flash Builder
    • Flash Builder 4
    • Flex 4
    • Flex Mobile
    • Framework
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • Mobile
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • SWIZ
    • Timer
    • Tree
    • Twitter
    • ViewStack
  • Advertisements

  • Recent Posts

    • Spooky Frenzy – iPad Game
    • Fountain Example
    • Reading & Writing files in Adobe AIR
    • CheckBox in List using MobileIconItemRenderer for Flex Mobile
    • Data Dependent decoratorClass in MobileIconItemRenderer Example
    • Flex 4 Resize Effect Example
    • Jump to next field using the Focus Manager
    • Searching Data using a Class Example
    • Flex Mobile: Two finger tap gesture to toggle actionBar visibility in a View (AIR for Android)
    • TabbedMobileApplication Example in Flex Mobile (AIR for Android)
  • Categories

    • Examples
    • Guest Poster
    • iOS
  • Archives

    • September 2011
    • July 2011
    • May 2011
    • March 2011
    • February 2011
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • November 2009
    • October 2009
    • March 2009
    • February 2009
  • Blogroll

    • Adobe Flex Jobs
    • NL for Business
  • Meta

    • Register
    • Log in
    • WordPress
    • XHTML

Copyright © 2010 Flex Blog · AdobeĀ® and AdobeĀ® Flex are registered trademarks of Adobe Systems.

WordPress Adobe Flex Adobe Flash Builder Adobe AIR Creative Commons License

  • Popular Posts

    • Progressbar in Datagrid Example 13 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 513 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 8 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 58 votes, average: 5.00 out of 5 (5.00 out of 5)
    • List Directory with AIR in Flex 4 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex FlashVars in AS3 Example 7 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 57 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Flex Dynamic Chart Example 4 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 54 votes, average: 5.00 out of 5 (5.00 out of 5)