Creating a toggleable MX LinkButton control in Flex 4

In a previous example, “Creating a toggleable LinkButton control in Flex”, we saw how you could create a toggleable Flex LinkButton control by extending the mx.skins.halo.LinkButtonSkin and adding custom “selectedUpSkin”, “selectedOverSkin”, “selectedDownSkin”, and “selectedDisabledSkin” skin states.

The following example shows how you can create a toggleable MX LinkButton control in Flex 4 by creating a custom MX LinkButton skin and specifying a background fill for the selected (“selectedUp”, “selectedOver”, “selectedDown”, and “selectedDisabled”) states.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see To download the latest nightly build of the Flex 4 SDK, see

For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:Application name="MX_LinkButton_toggle_test"
    <s:VGroup horizontalCenter="0" verticalCenter="0">
        <mx:LinkButton id="lb1"
                label="Default ({lb1.selected})"
                toggle="true" />
        <mx:LinkButton id="lb2"
                label="Custom ({lb2.selected})"
                skin="skins.MyLinkButtonSkin" />


And the custom MX LinkButton skin class, skins/MyLinkButtonSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- -->
<s:Skin name="MyLinkButtonSkin"
        minWidth="21" minHeight="21"
    <!-- states -->
        <s:State name="up" stateGroups="upStates"/>
        <s:State name="over" stateGroups="overStates"/>
        <s:State name="down" stateGroups="downStates" />
        <s:State name="disabled" stateGroups="disabledStates"/>
        <s:State name="selectedUp" stateGroups="selectedStates"/>
        <s:State name="selectedOver" stateGroups="selectedStates"/>
        <s:State name="selectedDown" stateGroups="selectedStates"/>
        <s:State name="selectedDisabled" stateGroups="selectedStates"/>
    <!-- layer 1: fill -->
    <s:Rect left="0" right="0" top="0" bottom="0" 
            excludeFrom="upStates,disabledStates" >
            <s:SolidColor color.overStates="{getStyle('rollOverColor')}" 
                    alpha="1.0" />


View source is enabled in the following example.

This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.

7 thoughts on “Creating a toggleable MX LinkButton control in Flex 4

  1. Hi Peter,
    I’m trying to set the rollOverColor property on a Halo LinkButton in MXML, without success.

    <mx:LinkButton label="Link" rollOverColor="#ff0000" />

    The rollover colour displays correctly in Flex SDK 3.5, but seems to be ignored in Flex 4 (Beta 2 release).

    1. @Chris,

      This code seems to work for me in Flex Rolling over the LinkButton control gives me a red background, pressing (and holding) the mouse button over the LinkButton control gives me an orange background:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx=""
          <mx:LinkButton id="linkBtn"
                  initialize="linkBtn.label = mx_internal::VERSION;" />


      1. Cheers Peter,
        Works with build in Flex 3 Builder (I couldn’t compile in current Flash Builder beta because of the Halo namespace change).

        I hadn’t noticed the issue with hit area until now :)

Comments are closed.