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;
        }
    }
}
 
Tagged with:
 
About The Author

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.

2 Responses to Removing the hand cursor from a disabled LinkButton control in Flex

  1. Geert says:

    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}" />
    
  2. Dan says:

    @Geert

    No… Actually you are binding to the ‘selected‘ property of a different control.

    You cannot bind to the ‘enabled‘ property. The following would not work:

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

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

Anti-Spam Protection by WP-SpamFree