Clearing a style on the Spark Button control in Flex 4

The following example shows how you can clear a style on the Spark Button control in Flex 4 by using the clearStyle() method.

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/10/27/clearing-a-style-on-the-spark-button-control-in-flex-4/ -->
<s:Application name="Spark_Button_clearStyle_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 label="bold" fontWeight="bold" click="btn.setStyle('fontWeight', FontWeight.BOLD);" />
        <s:Button label="no bold" click="btn.clearStyle('fontWeight');" />
    </s:controlBarContent>
 
    <fx:Script>
        <![CDATA[
            import flash.text.engine.FontWeight;
        ]]>
    </fx:Script>
 
    <s:Button id="btn"
            label="Button"
            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.

3 thoughts on “Clearing a style on the Spark Button control in Flex 4

  1. Thanks for your site and all the great examples!

    Is it possible to clear a style setting in an external CSS file? I would like to clear the “alternatingItemColors” style property on the Spark mobile LabelItemRenderer class so it would have a transparent background.

    I also want to be able to switch app-wide styling by loading one external CSS file or another, so using the clearStyle() method in code isn’t an option.

  2. To clarify my question, what would I put in my CSS file (excerpt below) to clear the existing property setting?

    s|LabelItemRenderer
    {
    alternatingItemColors : ???;
    }

Comments are closed.