In a previous example, “Creating an emphasized Spark Button control in Flex 4″, we saw how you could set the emphasized button state on a Flex 4 Spark Button control by setting the Boolean emphasized property.
The following example shows how you can style the Spark Button control’s emphasized state by setting the Button.emphasized CSS selector.
Full code after the jump.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 beta, check out the Adobe Flash Builder 4 page on the Adobe Labs site. To download the latest build of the Flex 4 SDK, see http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4. For instructions on using the beta Flex 4 SDK in Flex Builder 3, see "Using the beta Flex 4 SDK in Flex Builder 3".
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/03/03/styling-an-emphasized-fxbutton-control-in-flex-gumbo/ --> <s:Application name="Spark_Button_emphasized_style_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:controlBarContent> <s:CheckBox id="checkBox" label="emphasized" /> </s:controlBarContent> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/halo"; s|Button.emphasized { baseColor: red; } </fx:Style> <s:Button label="Spark Button label" emphasized="{checkBox.selected}" horizontalCenter="0" verticalCenter="0" /> </s:Application>
If you only wanted to style the emphasized state of certain buttons, you could use Flex 4’s Advanced CSS styling to style by id, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/03/03/styling-an-emphasized-fxbutton-control-in-flex-gumbo/ --> <s:Application name="Spark_Button_emphasized_style_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:controlBarContent> <s:CheckBox id="checkBox" label="emphasized" selected="true" /> </s:controlBarContent> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/halo"; s|Button#btn1.emphasized { baseColor: red; } </fx:Style> <s:VGroup horizontalCenter="0" verticalCenter="0"> <s:Button id="btn1" label="Spark Button" emphasized="{checkBox.selected}" /> <s:Button id="btn2" label="Spark Button" emphasized="{checkBox.selected}" /> </s:VGroup> </s:Application>
Or, you can style the emphasized state by setting the styleName property for certain buttons, as seen in the following example:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/03/03/styling-an-emphasized-fxbutton-control-in-flex-gumbo/ --> <s:Application name="Spark_Button_emphasized_style_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:controlBarContent> <s:CheckBox id="checkBox" label="emphasized" selected="true" /> </s:controlBarContent> <fx:Style> @namespace s "library://ns.adobe.com/flex/spark"; @namespace mx "library://ns.adobe.com/flex/halo"; s|Button.myButton.emphasized { baseColor: red; } </fx:Style> <s:VGroup horizontalCenter="0" verticalCenter="0"> <s:Button id="btn1" label="Spark Button" styleName="myButton" emphasized="{checkBox.selected}" /> <s:Button id="btn2" label="Spark Button" styleName="myButton" emphasized="{checkBox.selected}" /> <s:Button id="btn3" label="Spark Button" emphasized="{checkBox.selected}" /> </s:VGroup> </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.
