Displaying a hand cursor when mousing over a Flex control
I’ve seen this request come up a few times before in various mailing lists, forums and bug reports, so thought I’d do a brief post on it.
The following example shows how you can display a hand cursor when the user moves their mouse over an Image control in Flex by setting the useHandCursor property and buttonMode property to true, as seen in the following snippet:
<mx:Image source="image1.jpg" useHandCursor="true" buttonMode="true" />
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2007/11/18/displaying-a-hand-cursor-when-mousing-over-a-flex-control/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white"> <mx:ApplicationControlBar dock="true"> <mx:Form styleName="plain"> <mx:FormItem label="useHandCursor:"> <mx:CheckBox id="checkBox1" selected="true" /> </mx:FormItem> <mx:FormItem label="buttonMode:"> <mx:CheckBox id="checkBox2" selected="true" /> </mx:FormItem> </mx:Form> </mx:ApplicationControlBar> <mx:Image id="img" source="http://www.helpexamples.com/flash/images/image1.jpg" useHandCursor="{checkBox1.selected}" buttonMode="{checkBox2.selected}" /> </mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
21 Responses to Displaying a hand cursor when mousing over a Flex control
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


In this example it seems you don’t need to set useHandCursor. For example, uncheck useHandCursor. As long as you have buttonMode true it is always showing a hand cursor. Win XP FF2.0.0.9
Hi,
What if I would want to have the hand cursor when I roll over a UITextField component (like Labal) ?
In my case, I am creating a custom item renderer for the Tree component and right now I cannot use the hand cursor over the text.
Any help would be much appreciated !!
Hi,
If you want to set hand cursor in Label you must set mouseChildren=”false”
Chew, your comment made my life a lot easier. I wish LinkButton would wrap text, but your trick makes Text fields behave almost like LinkButtons. Sweet!
Ah just ran into the same thing and thanks to your comment I also turned a Text component into a button. Needed a multi-line linkbutton, but this trick with the text component worked wonders
Try this app it will be helpful for you to set hand cursor over any component
Is it possible to replace the image source on rollover to another image? When I tried the following, the image would just sit there and flicker when the mouse was over it..
I would just use a button (and skin it) instead, but I can’t use embeded resources. Any ideas?
Thanks!
Ned,
There are probably a few different techniques you can use, but you may have to embed the images for this to work. I think what is happening in your example is that when the image is rolled over, the existing image disappears when the new image is loaded. I *think* this would cause the
rollOutevent to get dispatched causing the first image to try and load again, putting it into a flickering loop.Try this:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ [Bindable] [Embed("image1.jpg")] private var img1:Class; [Bindable] [Embed("image2.jpg")] private var img2:Class; ]]> </mx:Script> <mx:Image id="image" source="{img1}" rollOver="image.source=img2;" rollOut="image.source=img1;" /> </mx:Application>Another example may be to load both images at once, stack them on top of each other and toggle the topmost image’s
visibleproperty:<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Canvas> <mx:Image id="rollOutImage" source="image1.jpg" rollOver="rollOverImage.visible = true;" /> <mx:Image id="rollOverImage" source="image2.jpg" visible="false" rollOut="rollOverImage.visible = false;" /> </mx:Canvas> </mx:Application>Happy Flexing!
Peter
Actually, setting the
rollOverandrollOuton the Canvas is better. Here’s a better example which adds some effects when the top image is shown or hidden:Peter
Hi,
it’s possible change Canvas backgroundColor and Label color properties using rollOver and rollOut events?
Thanks.
Filipe Torres,
Yes.
Peter
When you already have your mouse over a component with useHandCursor/buttonMode set to false, and you programmatically set useHandCursor/buttonMode to true, how do you revalidate the properties of the component, so that the hand cursor immediatly appears?
Without any revalidation, you must first move the cursor out of the component and then back in to see the hand cursor.
Example: Image can be clicked, then sends data to server and waits for response. It can only be clicked after it received the response.
Procedure: Image has hand cursor. On click, the hand cursor disappears and data is sent. The image has no hand cursor now. The response is received, the image may be clicked again, and shows a hand cursor. All without the user moving the cursor outside of the image area.
Thanks in advance.
Correction:
It seems, to see the hand cursor again, the user does not need to move the mouse out of the image and back in, but just to move it at all.
How can this be avoided?
@Jovica Aleksic,
In the following example I just set the
buttonModeproperty and the mouse cursor changes immediately (and without me moving the mouse).Peter
You are absolute right, your example works fine.
Will investigate later.
Thank you for these great examples….
Hi Peter,
I have a question for you. I have posted many qieries over here for. But unfortunately you haven’t rerplied to any. This query is of high importance to me and your help would be much appreciated.
I am draggin and dropping buttons(images are embedded on them) and dropping them on a canvas. Then if i click on any button on the canvas and hold it and move the mouse, a line is drawn connecting the button and the mouse. Now i have to connect the buttons if i leave my mouse on some other button. But i am not able to do so. If i leav the mouse on the canvas, a line is drawn. But if i leave it on any other button, a line is drawn from the first button to the origin of the canvas. What do i do to be able to identify the button when i drag my mouse over another button?
This is exactly what I was looking for… I love this blog! Thanks Peter!
Your blog is alweays a great help, thanks Peter!
Fantastic as usual Peter. Thanks