Removing the hand cursor from a disabled LinkButton control in Flex

by Peter deHaan on September 7, 2008

in LinkButton

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;
        }
    }
}

{ 2 comments… read them below or add one }

1 Geert October 6, 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}" />

Reply

2 Dan April 2, 2009 at 11:18 am

@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}" />

Reply

Leave a Comment

Sorry, this blog is terrible at eating HTML comments.
If you're pasting any HTML/XML/MXML code, you need to convert your < characters to &lt; and your > characters to &gt; .

You can 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

Previous post:

Next post: