Removing the selected highlight from the Spark ButtonBar control in Flex 4 (redux)

In a previous example, “Removing the selected highlight from the Spark ButtonBar control in Flex 4”, we saw how you can remove the selected highlight from the Spark ButtonBar control in Flex 4 by creating a custom ButtonBar and ButtonBarButton skin class.

The following example shows how you can remove the selected highlight from the Spark ButtonBar control in Flex 4 by extending the Spark ButtonBarButton class and creating a custom Spark ButtonBar skin.

The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, see www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.

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"?>
<!-- http://blog.flexexamples.com/2010/09/27/removing-the-selected-highlight-from-the-spark-buttonbar-control-in-flex-4-redux/ -->
<s:Application name="Spark_ButtonBarButton_selected_test"
        xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" 
        xmlns:mx="library://ns.adobe.com/flex/mx">
 
    <s:ButtonBar id="tbb"
            skinClass="skins.CustomSparkButtonBarSkin"
            horizontalCenter="0" verticalCenter="0">
        <s:dataProvider>
            <s:ArrayList source="[red,orange,yellow,green,blue]" />
        </s:dataProvider>
    </s:ButtonBar>
 
</s:Application>

The custom Spark ButtonBarButton class, comps/CustomSparkButtonBarButton.as, is as follows:

/** http://blog.flexexamples.com/2010/09/27/removing-the-selected-highlight-from-the-spark-buttonbar-control-in-flex-4-redux/ */
package comps {
    import spark.components.ButtonBarButton;
 
    public class CustomSparkButtonBarButton extends ButtonBarButton {
        public function CustomSparkButtonBarButton() {
            super();
        }
 
        override public function set selected(value:Boolean):void {
            // ignore
        }
    }
}

And the custom Spark ButtonBar skin, skins/CustomSparkButtonBarSkin.mxml, is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2010/09/27/removing-the-selected-highlight-from-the-spark-buttonbar-control-in-flex-4-redux/ -->
<s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:comps="comps.*"
        alpha.disabled="0.5">
    <s:states>
        <s:State name="normal" />
        <s:State name="disabled" />
    </s:states>
 
    <fx:Metadata>
        [HostComponent("spark.components.ButtonBar")]
    </fx:Metadata> 
 
    <fx:Declarations>
        <fx:Component id="firstButton">
            <comps:CustomSparkButtonBarButton skinClass="spark.skins.spark.ButtonBarFirstButtonSkin" />
        </fx:Component>
 
        <fx:Component id="middleButton" >
            <comps:CustomSparkButtonBarButton skinClass="spark.skins.spark.ButtonBarMiddleButtonSkin" />
        </fx:Component>
 
        <fx:Component id="lastButton" >
            <comps:CustomSparkButtonBarButton skinClass="spark.skins.spark.ButtonBarLastButtonSkin" />
        </fx:Component>
    </fx:Declarations>
 
    <s:DataGroup id="dataGroup" width="100%" height="100%">
        <s:layout>
            <s:ButtonBarHorizontalLayout gap="-1"/>
        </s:layout>
    </s:DataGroup>
 
</s:Skin>

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.