Removing the default corner radius on the Spark ButtonBar control in Flex 4

The following example shows how you can remove the default corner radius on the Spark ButtonBar control in Flex 4 by creating a custom skin and setting the skinClass style.

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/2009/03/11/removing-the-default-corner-radius-on-the-fxbuttonbar-control-in-flex-gumbo/ -->
<s:Application name="Spark_ButtonBar_skinClass_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">
 
    <fx:Declarations>
        <s:ArrayList id="arrColl"
                source="[The,Quick,Brown,Fox]" />
    </fx:Declarations>
 
    <mx:Form horizontalCenter="0" verticalCenter="0">
        <mx:FormItem label="default:">
            <s:ButtonBar id="btnBar1"
                    dataProvider="{arrColl}" />
        </mx:FormItem>
        <mx:FormItem label="custom:">
            <s:ButtonBar id="btnBar2"
                    dataProvider="{arrColl}"
                    skinClass="skins.CustomButtonBarSkin"/>
        </mx:FormItem>
    </mx:Form>
 
</s:Application>

Next, in the custom Spark ButtonBar skin file, skins/CustomButtonBarSkin.mxml, simply remove the firstButton and lastButton declarations, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/11/removing-the-default-corner-radius-on-the-fxbuttonbar-control-in-flex-gumbo/ -->
<s:Skin name="CustomButtonBarSkin"
        xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark" 
        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="middleButton" >
            <s:ButtonBarButton skinClass="spark.skins.spark.ButtonBarMiddleButtonSkin" />
        </fx:Component>
    </fx:Declarations>
 
    <s:DataGroup id="dataGroup" width="100%" height="100%">
        <s:layout>
            <s:ButtonBarHorizontalLayout gap="-1"/>
        </s:layout>
    </s:DataGroup>
 
</s:Skin>

You can also set the skinClass style in an external .CSS file or <Style/> block, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/11/removing-the-default-corner-radius-on-the-fxbuttonbar-control-in-flex-gumbo/ -->
<s:Application name="Spark_ButtonBar_skinClass_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">
 
    <fx:Style>
        @namespace s "library://ns.adobe.com/flex/spark";
        @namespace mx "library://ns.adobe.com/flex/mx";
 
        s|ButtonBar {
            skinClass: ClassReference("skins.CustomButtonBarSkin");
        }
    </fx:Style>
 
    <fx:Declarations>
        <s:ArrayList id="arrColl"
                source="[The,Quick,Brown,Fox]" />
    </fx:Declarations>
 
    <s:ButtonBar id="btnBar2"
            dataProvider="{arrColl}"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

Or, you can set the skinClass style using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2009/03/11/removing-the-default-corner-radius-on-the-fxbuttonbar-control-in-flex-gumbo/ -->
<s:Application name="Spark_ButtonBar_skinClass_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:controlBarContent>
        <s:Button id="btn"
                label="Set button skin class"
                click="btn_clickHandler(event);" />
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import skins.CustomButtonBarSkin;
 
            protected function btn_clickHandler(evt:MouseEvent):void {
                btnBar2.setStyle("skinClass", CustomButtonBarSkin);
            }
        ]]>
    </fx:Script>
 
    <fx:Declarations>
        <s:ArrayList id="arrColl"
                source="[The,Quick,Brown,Fox]" />
    </fx:Declarations>
 
    <s:ButtonBar id="btnBar2"
            dataProvider="{arrColl}"
            horizontalCenter="0" verticalCenter="0" />
 
</s:Application>

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.