Adding a pointer/hand cursor to Flex UI Controls using CSS and Skin Classes
Saturday, July 17th, 2010By default, Flex controls which can be "clicked" on by a user do not change the mouse cursor to the hand or pointer cursor when you "mouse over" them. This is a bit annoying as users now rely on this visual feedback as it is the default behaviour of HTML links on web pages.
It is simple to make a Flex control opperate like this, by setting its useHandCursor and buttonMode properties to true. However, this is not very convenient to do for every component in an application, leading some to extend each component in order to add this behaviour as default.
As this is also far from a perfect solution, my team wondered if we could use skinning to add this behaviour - after all it is presentational. Although there is no direct way to do this through a skin class, it turns out that one can access the component the skin is applied to, thought the parent property. So as the following ButtonSkin class shows, you can indeed use a Skin, applied to each Button using CSS, to set the use of a hand cursor.
/**
** Copywrite (c) 2010, David Beale**/package com.bealearts.skin.component{import mx.controls.Button;import mx.skins.halo.ButtonSkin;;/**
* Skin which adds a mouse-over hand cursor to a Button component*/public class ButtonSkin extends mx.skins.halo.ButtonSkin{/* PUBLIC *//**
* Constructor*/public function ButtonSkin(){super();}/* PROTECTED *//**
* Override to set hand cursor property of the parent component*/override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{/* LOCALS */var button:Button = null;super.updateDisplayList(unscaledWidth, unscaledHeight);// Get componentif (this.parent){// Get component - note not every component will be a direct parent of a skinbutton = Button(this.parent);// Set Button modeif (!button.buttonMode)button.buttonMode = true;// Set Hand cursorif (!button.useHandCursor)button.useHandCursor = true;}}/* PRIVATE */}}- Download this code: ButtonSkin.as_.txt
