07
Sep
08

Removing the hand cursor from a disabled LinkButton control in Flex

The following example shows how you can remove the hand cursor from the a Flex LinkButton control by extending the LinkButton class, overriding the enabled setter function, and setting the useHandCursor property.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/07/removing-the-hand-cursor-from-a-disabled-linkbutton-control-in-flex/ -->
<mx:Application name="LinkButton_useHandCursor_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        xmlns:comps="comps.*"
        layout="horizontal"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:ApplicationControlBar dock="true">
        <mx:Form styleName="plain">
            <mx:FormItem label="enabled:">
                <mx:CheckBox id="checkBox" selected="true" />
            </mx:FormItem>
        </mx:Form>
    </mx:ApplicationControlBar>

    <mx:LinkButton id="linkButton"
            label="Default LinkButton"
            enabled="{checkBox.selected}" />

    <comps:DisabledLinkButtonMXML id="linkButton2"
            label="Custom LinkButton (MXML)"
            enabled="{checkBox.selected}" />

    <comps:DisabledLinkButtonAS id="linkButton3"
            label="Custom LinkButton (ActionScript)"
            enabled="{checkBox.selected}" />

</mx:Application>

View source is enabled in the following example.

comps/DisabledLinkButtonMXML.mxml

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/09/07/removing-the-hand-cursor-from-a-disabled-linkbutton-control-in-flex/ -->
<mx:LinkButton xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[
            override public function set enabled(value:Boolean):void {
                super.enabled = value;
                useHandCursor = value;
            }
        ]]>
    </mx:Script>

</mx:LinkButton>

comps/DisabledLinkButtonAS.as

/**
 * http://blog.flexexamples.com/2008/09/07/removing-the-hand-cursor-from-a-disabled-linkbutton-control-in-flex/
 */
package comps {
    import mx.controls.LinkButton;

    public class DisabledLinkButtonAS extends LinkButton {

        /**
         * Constructor.
         */
        public function DisabledLinkButtonAS() {
            super();
        }

        /**
         * @private
         */
        override public function set enabled(value:Boolean):void {
            super.enabled = value;
            useHandCursor = value;
        }
    }
}

1 Response to “Removing the hand cursor from a disabled LinkButton control in Flex”


  1. 1 Geert Oct 6th, 2008 at 5:49 am

    Why would you need to extend the LinkButton?
    Setting the ‘useHandCursor‘ property to the same value as the ‘enabled‘ property works just fine:

    <mx:LinkButton id="linkButton"
                label="Default LinkButton"
                enabled="{checkBox.selected}"
                useHandCursor="{checkBox.selected}" />
    

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".