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!

    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
  • Guest Poster
  • Forum
  • Contact Us
Subscribe to Flex BlogSubscribe
  • Examples
Browse > Home / Examples / Set custom cursor using the CursorManager

Set custom cursor using the CursorManager

18 November 2009

Line Break

Author: Roelof (11 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, travelling or just being lazy. 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?

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

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

  • Sponsors

  • Popular Tags

    • AdvancedDataGrid
    • AIR
    • ArrayCollection
    • baseColor
    • Button
    • CursorManager
    • DataGrid
    • Dynamic
    • Effects
    • File
    • Flash Builder
    • Flash Builder 4
    • Flashvars
    • Flex 4
    • Framework
    • HSlider
    • Icon
    • Image
    • itemRenderer
    • LinkBar
    • PHP
    • ProgressBar
    • Repeater
    • Style
    • SWIZ
    • Timer
    • Tree
    • Twitter
    • ViewStack
    • VSlider
  • Flex Blog Readers

  • Flex Jobs (from Flex Jobs.org)

    Your Job here? Post your job @ Flex Jobs.org

    Advertisement

  • Recent Posts

    • SWIZ Framework in Flex 4 Example: Part I
    • Dynamic AdvancedDataGridColumn in Flex 4
    • How to make a magnetic button in Flex 4
    • Using ASDoc as an External Tool in Flash Builder 4
    • Flex Encryption (MD5, SHA1, SHA224, SHA256, HMAC)
    • The SWIZ framework for Flex 3 / Flex 4: Easy, Light and Very Powerfull
    • Call Javascript function from Flex / Flash Builder (AS3)
    • Flex FlashVars in AS3 Example
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction
    • WordPress Flash / Flex Comments Form
  • Categories

    • Examples
    • Guest Poster
  • Archives

    • 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

    • List Directory with AIR in Flex 4 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Control Webpage in HTML Control in AIR 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Data Dependant Tree Icon with Tree in AdvancedDataGrid with iconFunction 5 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 55 votes, average: 5.00 out of 5 (5.00 out of 5)
    • Progressbar in Datagrid 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)
    • WordPress Flash / Flex Comments Form 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)