Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy 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
Promotions
Estimated shipping
Tax
Calculated at checkout
Total
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex in a Week /

Exercise 5.8: Animating Button components

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use skin states
  • Animate skin transitions

Modified

23 May 2011

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flash BuilderFlexRIA
Was this helpful?
Yes   No

By clicking Submit, you accept the Adobe Terms of Use.

 
Thanks for your feedback.

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.7 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).

Note that the Submit Button control is skinned and resembles the title skin.
Figure 3. Note that 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 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>
  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 5.10: Creating a production build
  • Exercise 3.4: Passing data to the server with the WebService class
  • Exercise 3.7: Using two-way binding
  • Exercise 2.8: Creating an ArrayCollection of value objects
  • Exercise 3.4: Passing data to the server with the RemoteObject class
  • Exercise 3.6: Validating form data
  • Exercise 4.4: Using the Spark DataGrid control
  • Exercise 4.6: Navigating using navigator containers
  • Exercise 5.1: Using text controls
  • Exercise 4.7: Creating and navigating application states

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

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 © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement