23 May 2011
Beginning
In this exercise you will learn how to use a skin to animate Button states (see Figure 1).
In this exercise, you will learn how to:
In this section, you will use the provided ButtonWithStatesSkin skin to apply a skin to multiple Button control states.
You should see the application shown in Figure 2.
Properties of the parent comment, locate the states block.Note the four State instances. The up, over, down, and disabled states are required for a Button component skin.
<s:states>
<s:State name="up"/>
<s:State name="over"/>
<s:State name="down"/>
<s:State name="disabled"/>
</s:states>
UI Components comment.Label control, add a Rect primitive block.<!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<s:Rect>
</s:Rect>
<s:Label id="labelDisplay"
Rect tag, add the id property with a value of buttonColor.<s:Rect id="buttonColor">
</s:Rect>
top, bottom, left and right properties all with a value of 0.<s:Rect id="buttonColor"
top="0" bottom="0" left="0" right="0">
</s:Rect>
topRightRadiusX property with a value of 3.<s:Rect id="buttonColor"
top="0" bottom="0" left="0" right="0"
topRightRadiusX="3">
Rect block, create a fill block.<s:Rect id="buttonColor"
top="0" bottom="0" left="0" right="0"
topRightRadiusX="3">
<s:fill>
</s:fill>
</s:Rect>
fill block, add a SolidColor instance....
<s:fill>
<s:SolidColor/>
</s:fill>
...
SolidColor instance, add the color.up property with a value of 0x0D86B8 (blue)....
<s:fill>
<s:SolidColor color.up="0x0D86B8"/>
</s:fill>
...
SolidColor graphic, add the color.over property with a value of 0x64BC48 (green).<s:fill>
<s:SolidColor color.up="0x0D86B8"
color.over="0x64BC48"/>
</s:fill>
SolidColor graphic, add the color.down property with a value of 0x555555 (dark grey)....
<s:fill>
<s:SolidColor color.up="0x0D86B8" color.over="0x64BC48"
color.down="0x555555"/>
</s:fill>
...
UI components comment, locate the Button control.Button control, add the skinClass property with a value of skins.ButtonWithStatesSkin as the skinClass.<s:Button label="SUBMIT"
fontWeight="bold"
skinClass="skins.ButtonWithStatesSkin"/>
You should see the Submit Button control resembles the application's title skin (see Figure 3).
Button control.You should see the Button control turns green, as shown in Figure 4.
Button control.You should see the dark grey down state of the Button control (see Figure 5).
In this section, you will create an animation that plays between Button control states.
states tags, create a transitions block....
</s:states>
<s:transitions>
</s:transitions>
transitions block, create a Transition block.<s:transitions>
<s:Transition>
</s:Transition>
</s:transitions>
Transition tag, add the fromState property with a value of up and the toState property with a value of over....
<s:Transition fromState="up" toState="over">
</s:Transition>
...
Transition block, create a Resize effect.<s:Transition fromState="up" toState="over">
<s:Resize/>
</s:Transition>
Resize tag, bind the buttonColor Rect primitive as the target and assign 25 as the widthBy.<s:Transition fromState="up" toState="over">
<s:Resize target="{buttonColor}" widthBy="25"/>
</s:Transition>
Button control.You should see the Button control resizes, but reverts to its original dimensions, causing the final over state to appear as shown in Figure 6.
Rect primitive, assign 90 as the over State width.<s:Rect id="buttonColor"
top="0" bottom="0" left="0" right="0"
topRightRadiusX="3"
width.over="90">
...
</s:Rect>
Button control.You should see the Button control resize and remain resized in the over state (see Figure 7).
Button control.You should see there is no animation to resize the button to the up State width.
Button control.You should see the Button control does return to the original width, but animates to a larger size first.
Transition tag add the autoReverse property and set the value to true. This will reverse the button's animation when you mouse away from the Button control. The alternative is creating another Transition block with the fromState and toState values reversed and the widthBy value for the Resize effect set to a negative number.<s:transitions>
<s:Transition fromState="up" toState="over" autoReverse="true">
<s:Resize target="{buttonColor}" widthBy="25"/>
</s:Transition>
</s:transitions>
You should see that the Button control resizes appropriately when you mouse away. However, notice that the down state of the button is not the same size as the over state.
Rect block.Rect primitive, add the width.down property with a value of 90.<s:Rect id="buttonColor"
top="0" bottom="0" left="0" right="0"
topRightRadiusX="3"
width.over="90" width.down="90">
...
</s:Rect>
You should see that the width of the Button control is the same for the over and down states (see Figure 8).
You should see the Submit button return to its original size.
In this exercise you learned how to use a skin to animate Button states.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.