Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Exercise 5.8: Animating Button components

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use skin states
  • Animate skin transitions

Modified

2 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash Builder Flex RIA

Requirements

Prerequisite knowledge

  • Exercise 1.1: Setting up Flash Builder and your project files
  • Exercise 5.1: Using text controls
  • Exercise 5.2: Defining selector styles
  • Exercise 5.3: Using advanced CSS selectors
  • Exercise 5.5: Creating and applying skins
  • Exercise 5.6: Creating custom skin properties
  • Exercise 5.7: Creating a vertical title bar on a Panel container

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Exercise files

  • ex5_08_starter.zip
  • ex5_08_solution.zip

In this exercise you will learn how to use a skin to animate Button states (see Figure 1).

Review your task for this exercise.
Figure 1. Review your task for this exercise.

In this exercise, you will learn how to:

  • Use skin states
  • Animate skin transitions

Use skin states

In this section, you will use the provided ButtonWithStatesSkin skin to apply a skin to multiple Button control states.

  1. Download the ex5_08_starter.zip file provided in the Exercise files section and extract the ex5_08_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex5_08_starter.fxp file.
  4. From the Package Explorer view, open the ex5_08_starter.mxml file.
  5. Run the application.

    You should see the application shown in Figure 2.

 Run the application.
Figure 2. Run the application.
  1. Return to Flash Builder.
  2. From the Package Explorer view, locate the skins package and open the ButtonWithStatesSkin.mxml file.
  3. Below the 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>
  1. Locate the UI Components comment.
  2. Between the comment and the Label control, add a Rect primitive block.
<!-- UI components ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <s:Rect> </s:Rect> <s:Label id="labelDisplay"
  1. To the opening Rect tag, add the id property with a value of buttonColor.
<s:Rect id="buttonColor"> </s:Rect>
  1. Add the 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>
  1. Add the topRightRadiusX property with a value of 3.
<s:Rect id="buttonColor" top="0" bottom="0" left="0" right="0" topRightRadiusX="3">
  1. Within the 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>
  1. Within the fill block, add a SolidColor instance.
... <s:fill> <s:SolidColor/> </s:fill> ...
  1. To the nested SolidColor instance, add the color.up property with a value of 0x0D86B8(blue).
... <s:fill> <s:SolidColor color.up="0x0D86B8"/> </s:fill> ...
  1. To the 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>
  1. To the 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> ...
  1. Save the file.
  2. From the Package Explorer view, components package, open the EmployeeDirectory.mxml file.
  3. Below the UI components comment, locate the Button control.
  4. To the Button control, add the skinClass property with a value of skins.ButtonWithStatesSkin as the skinClass.
<s:Button label="SUBMIT" fontWeight="bold" skinClass="skins.ButtonWithStatesSkin"/>
  1. Save the file and run the application.

    You should see the Submit Button control resembles the application's title skin (see Figure 3).

Notice the Submit Button control is skinned and resembles the title skin.
Figure 3. Notice the Submit Button control is skinned and resembles the title skin.
  1. Mouse over the Submit Button control.

    You should see the Button control turns green, as shown in Figure 4.

 Mouse over the Button control to display the green over state.
Figure 4. Mouse over the Button control to display the green over state.
  1. Click and hold the Button control.

    You should see the dark grey down state of the Button control (see Figure 5).

Click and hold the Button control to see the dark grey down State.
Figure 5. Click and hold the Button control to see the dark grey down State.

Animate skin transitions

In this section, you will create an animation that plays between Button control states.

  1. Return to the ButtonWithStatesSkin.mxml file in Flash Builder.
  2. Below the states tags, create a transitions block.
... </s:states> <s:transitions> </s:transitions>
  1. Within the transitions block, create a Transition block.
<s:transitions> <s:Transition> </s:Transition> </s:transitions>
  1. To the opening 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> ...
  1. Within the Transition block, create a Resize effect.
<s:Transition fromState="up" toState="over"> <s:Resize/> </s:Transition>
  1. To the 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>
  1. Save the file and run the application.
  2. Mouse over the Submit 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.

 Mouse over the Send button to see the animation play, but not affect the final size of the Button control.
Figure 6. Mouse over the Send button to see the animation play, but not affect the final size of the Button control.
  1. Return to the ButtonWithStatesSkin.mxml file in Flash Builder.
  2. To the 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>
  1. Save the file and run the application.
  2. Mouse over the Submit Button control.

    You should see the Button control resize and remain resized in the over state (see Figure 7).

 Mouse over the Send Button control to see it resize.
Figure 7. Mouse over the Send Button control to see it resize.
  1. Move the mouse away from the Button control.

    You should see there is no animation to resize the button to the up State width.

  2. Click the Button control.

    You should see the Button control does return to the original width, but animates to a larger size first.

  3. Return to the ButtonWithStatesSkin.mxml file in Flash Builder.
  4. To the opening 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>
  1. Save the file and run the application.
  2. Mouse over and then mouse away from the Submit button.

    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.

  3. Return to Flash Builder.
  1. Locate the Rect block.
  2. To the Rect primitive, add 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>
  1. Save the file and run the application.
  2. Mouse over the Submit button to trigger the transition.
  3. Click the Submit button.

    You should see that the width of the Button control is the same for the over and down states (see Figure 8).

The down state of the Button control
Figure 8. The down state of the Button control.
  1. Mouse away from the Submit button.

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.

Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License+Adobe Commercial Rights

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.

More Like This

  • Exercise 1.2: Creating an application user interface
  • Exercise 1.3: Generating an email address using data binding
  • Exercise 1.4: Adding data to your application
  • Exercise 1.5: Experimenting with container layouts
  • Exercise 1.6: Creating MXML custom components with ActionScript properties
  • Exercise 1.1: Setting up your project files
  • Exercise 2.5: Retrieving and handling data with the RemoteObject object
  • Exercise 2.6: Separating the model, view, and controller
  • Exercise 2.7: Creating an ActionScript class and instances
  • Exercise 2.8: Creating an ArrayCollection of value objects

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement