In this exercise, you will use skin states to skin a Button control, and then apply a state transition to the Button control to
animate it (see Figure 1).

Figure 1. You will skin and animate the button in this application.
In this exercise, you will learn how to:
In order to complete this tutorial, you need the following software and files:
In this section, you will use the provided
ButtonWithStatesSkin component to apply a skin to multiple Button control states.
Locate the pseudo
selectors for the Button control states and disable them by
commenting them out (see Figure 2).

Figure 2. Add comments to keep the Button control pseudo selectors from running.
Save the file and run the application.
You should see the Button controls within
the application have default states defined (see Figure 3).

Figure 3. See the Button controls within the application have default skins.
Notice the following things:
The Script tag has the labelElement skin part excluded from the colors of the
graphic element Rect.
<fx:Script>
<![CDATA[
static private const exclusions:Array = ["labelElement"];
override public function get colorizeExclusions():Array {return exclusions;}
]]>
</fx:Script>
The states block defines the states for Button controls.
<s:states>
<s:State name="up"/>
<s:State name="over"/>
<s:State name="down"/>
<s:State name="disabled"/>
</s:states>
The Rect block defines the fill colors for the states. Note the fill.up, fill.down, fill.over tags each has a different SolidColor property value.
<s:Rect id="buttonColor" left="0" right="0" top="0" bottom="0">
<s:fill.up>
<mx:SolidColor color="0x555555"/>
</s:fill.up>
<s:fill.over>
<mx:SolidColor color="0xD9E028"/>
</s:fill.over>
<s:fill.down>
<mx:SolidColor color="0xD9E028"/>
</s:fill.down>
</s:Rect>
The Label control with the id property value of labelElement defines
the Button control's label as a separate skin part with specific style definitions.
<s:Label id="labelElement"
textAlign="center"
verticalAlign="middle"
color="0x000000"
fontWeight="bold"
horizontalCenter="0"
verticalCenter="1"
left="10" right="10"
top="2" bottom="2">
</s:Label>
Properties of the parent comment. Move the opening comment so that the states tag block is outside the commented area (see Figure 4).

Figure 4. Move the states tag block from within the commented area.
Rect tag block. Move the Rect tag block from
within the comments.
<s:Rect id="buttonColor"
left="0" right="0"
top="0" bottom="0">
<s:fill.up>
<mx:SolidColor color="0x555555"/>
</s:fill.up>
<s:fill.over>
<mx:SolidColor color="0xD9E028"/>
</s:fill.over>
<s:fill.down>
<mx:SolidColor color="0x0D86B8"/>
</s:fill.down>
</s:Rect>
<!--
<s:Label id="labelElement"
text="Send"
textAlign="center"
verticalAlign="middle"
color="0x000000"
fontWeight="bold"
horizontalCenter="0" verticalCenter="1"
left="10" right="10"
top="2" bottom="2">
</s:Label>
-->
Button control.To the Button control, assign
the skinClass property value to skins.ButtonWithStatesSkin.
<s:Button label="Send"
textAlign="center"
skinClass="skins.ButtonWithStatesSkin"/>
Save the file and run the application.
The button in the Employee of the Month panel should appear as shown in Figure 5.

Figure 5. Skin the Button control located within the EmployeeOfTheMonth component.
Locate the Label control and
remove the surrounding comments.
<!-- UI components
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<s:Rect id="buttonColor"
left="0" right="0"
top="0" bottom="0">
...
</s:Rect>
<s:Label id="labelElement"
text="Send"
textAlign="center"
verticalAlign="middle"
color="0x000000"
fontWeight="bold"
horizontalCenter="0"
verticalCenter="1"
left="10" right="10"
top="2" bottom="2">
</s:Label>
The button in the Employee of the Month panel now has a label (see Figure 6).

Figure 6. Add a label to the Button control.
In this section you will use the provided code within the
ButtonWithStatesSkin.mxml file to apply a state transition to a Button control.
states tags, remove the comments from around the transitions block.Within the transitions block note the following:
The Transition tag with a fromState property value of up and a toState property value
of over defines the transition from the up state of a Button control to the
over state.
<s:Transition fromState="up" toState="over">
<s:Sequence targets="{labelElement, buttonColor}">
<s:Resize widthBy="15"/>
</s:Sequence>
</s:Transition>
The Sequence tag within the first Transition tag block has the targets property value assigned to the labelElement Label control and the buttonColor
Rect class.
<s:Transition fromState="up" toState="over">
<s:Sequencetargets="{labelElement, buttonColor}">
<s:Resize widthBy="15"/>
</s:Sequence>
</s:Transition>
Within the Sequence tags, the Resize effect is used
to expand the width of the Button control by 15 pixels:
<s:Transition fromState="up" toState="over">
<s:Sequence targets="{labelElement, buttonColor}">
<s:Resize widthBy="15"/>
</s:Sequence>
</s:Transition> You should see the button animate its width (see Figure 7).

Figure 7. Create a transition animation for the Button control between the up and over states.
<Transition> tag with a fromState property and a toState property to animate buttons.Trilemetry, Inc is a development and education organization that implements a human-centered design approach to the creation of software and content. Their Adobe portfolio includes the Adobe ColdFusion Getting Started Experience, the Adobe Flex Getting Started Experience, the Flex in a Week video series, the official Adobe instructor-led training course Flex 3: Extending and Styling Components and more. They also create and support many Web applications from interactive Flash sites and corporate web sites to mission-critical business applications.