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 http://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, see http://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.

 
Tagged with:
 
About The Author

Peter deHaan

Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.

3 Responses to Clearing a style on the Spark Button control in Flex 4

  1. Hi
    Again i wrote a full action script version of this post please visit setstyle-and-clearstyle-usages-for-spark-button-control-in-flex4-using-as3

    thanks for posing nice tutorials daily it help me lot to learn flex quickly, thanks again

  2. 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.

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

    s|LabelItemRenderer
    {
    alternatingItemColors : ???;
    }

Leave a Reply

Your email address will not be published.

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