Setting Styles
Use the <mx:SetStyle> tag
to set styles for components when defining states. You set
styles when you want to change the appearance (such as the color or font)
of a component when its state changes. The <mx:SetStyle> tag has the same attributes
as the <mx:SetProperty> tag. The
target property allows you to reference
the component to which you want to apply the style, the name attribute allows you to specify the style
you want to set, and the value
attribute allows you to set the value of the style.
Example 12-9 uses three buttons to toggle among three states. Each state sets the color styles of checkboxes to highlight groups of transportation types (land, air, and water). For example, when the user clicks the Land button, the car, train, and motorcycle checkbox labels are displayed using a red font.
Example 12-9. Setting styles
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:VBox id="vbox"> <mx:HBox> <mx:Button id="land" label="Land" click="currentState='landState';" /> <mx:Button id="air" label="Air" click="currentState='airState';" /> <mx:Button id="water" label="Water" click="currentState='waterState';" /> </mx:HBox> <mx:CheckBox id="helicopter" label="Helicopter" /> <mx:CheckBox id="motorcycle" label="Motorcycle" /> <mx:CheckBox id="car" label="Car" /> <mx:CheckBox id="airplane" label="Airplane" /> <mx:CheckBox id="train" label="Train" /> <mx:CheckBox id="boat" label="Boat" /> <mx:CheckBox id="submarine" ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access