Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
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 / Flex in a Week /

Exercise 5.9: Skinning the SkinnableDataContainer container

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use the SkinnableDataContainer component
  • Apply a skin to the SkinnableDataContainer component
  • Create the hover state

Modified

23 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 4.1: Passing data to item renderers for display
  • Exercise 4.2: Displaying dynamic data in a custom item renderer
  • Exercise 5.5: Creating and applying skins

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Exercise files

  • ex5_09_starter.zip
  • ex5_09_solution.zip

In Day 4 you created a Spark item renderer, which you applied to the repeated data elements in the DataGroup container. You added some visual enhancements to the item renderer but not to the DataGroup container itself.

In this exercise you will change the DataGroup container to a SkinnableDataContainer container so that you can apply a skin to it (see Figure 1). It is the gray rounded rectangle around all of the employee data elements.

You will also create a new hover state display for the items.

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

In this exercise you will learn how to:

  • Use the SkinnableDataContainer component
  • Create and apply a skin to the SkinnableDataContainer component
  • Create the hover state

Use the SkinnableDataContainer component

In this section you will change the DataGroup container (used in Exercises 4.1 and 4.2) to a SkinnableDataContainer container so that you can apply a skin to it.

  1. Download the ex5_09_starter.zip file provided in the Exercise files section and extract the ex5_09_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex5_09_starter.fxp file.
  4. Open ex5_09_starter.mxml.
  5. Run the application.

    You should see the application appears as shown in Figure 2. The item renderer used for the data in this application was created in Exercise 4.2: Displaying dynamic data in a custom item renderer.

Run the application.
Figure 2. Run the application.
  1. Return to the ex5_09_starter.mxml file in Flash Builder.
  2. Below the UI components comment, locate the DataGroup container.
  3. Change the DataGroup container into a SkinnableDataContainer component.
<s:SkinnableDataContainer dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer"/>
  1. Save the file and run the application.

You should see no change in the application.

Apply a skin to the SkinnableDataContainer component

In this section, you will create a skin and apply it to the SkinnableDataGroup container.

  1. Return to the ex5_09_starter.mxml file in Flash Builder.
  2. Highlight the opening SkinnableDataContainer tag and switch to Design mode.
  3. In the Properties view for the SkinnableDataContainer, locate the Skin field in the Style segment.
  4. Click the icon to the right of the Skin field and select Create Skin (see Figure 3).
Click the Create Skin option in the Properties view
Figure 3. Click the Create Skin option in the Properties view.
  1. In the New MXML Skin dialog box, type skins for the Package and type BackgroundSkin for the Name.
 Fill out the New MXML Skin dialog box.
Figure 4. Fill out the New MXML Skin dialog box.
  1. Click Finish.

    You should see the BackgroundSkin.mxml file open in the Editor view.

  2. Note that the file is configured with the SkinnableDataContainer class as its host component class. It also contains a states block with the required State tags and a DataGroup container.

    Remember that containers like the Group, Application, and Panel container have a skin part named contentGroup. For the DataGroup container, the skin part is named dataGroup.

  3. Below the states block, create a Rect primitive block.
<s:states> <s:State name="normal" /> <s:State name="disabled" /> </s:states> <s:Rect> </s:Rect>
  1. To the Rect primitive, add the height property with a value of 100%, the width property with a value of 120 and the radiusX and radiusY properties, both with a value of 4.
<s:Rect height="100%" width="120" radiusX="4" radiusY="4"> </s:Rect>
  1. Within the Rect block, create a fill block.
<s:Rect height="100%" width="120" radiusX="4" radiusY="4"> <s:fill> </s:fill> </s:Rect>
  1. Within the fill block, create a SolidColor graphic and add the alpha property with a value of .4 and the color property with a value of 0x000000.
<s:Rect height="100%" width="120" radiusX="4" radiusY="4"> <s:fill> <s:SolidColor alpha=".4" color="0x000000"/> </s:fill> </s:Rect>
  1. Save the file.
  2. Return to the ex5_09_starter.mxml file and switch to Source mode.
  3. In the SkinnableDataContainer container, note that the skinClass property has been added with a value of skins.BackgroundSkin.
<s:SkinnableDataContainer dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer" skinClass="skins.BackgroundSkin"/>
  1. Save the file and run the application.

    You should see the skin applied to the SkinnableDataGroup container (see Figure 5). Note that the content is not centered within the skin.

 Run the application to sthe skinned SkinnableDataContainer component.
Figure 5. Run the application to sthe skinned SkinnableDataContainer component.
  1. Return to the BackgroundSkin.mxml file in Flash Builder.
  2. To the DataGroup container, add the horizontalCenter property with a value of 0.
<s:DataGroup id="dataGroup" ... horizontalCenter="0"> ... </s:DataGroup>
  1. From the DataGroup container, remove the left, right, and top properties.
  2. To the DataGroup container, reassign the bottom property with a value of 5.
  3. Save the file and run the application.

The data is now centered within the skin (see Figure 6). Note that when you mouse over an employee there is a small rectangle that indicates you are hovering over an item. This occurs because you have set the top property in the BorderContainer of the EmployeeItemRenderer class. Next, you will modify the hovered state of the item renderer.

Run the application to see the data centered in the skin.
Figure 6. Run the application to see the data centered in the skin.

Create the hover state

In this section you will create the hover state for the content in the DataGroup container.

  1. Return to Flash Builder and open the EmployeeItemRenderer.mxml file from the components package.
  2. Locate the BorderContainer and cut the top property from the opening tag.
  3. Save the file.
  4. Open the BackgroundSkin.mxml file and paste the top property into the opening tag from the DataGroup container.
  5. Change the value of the bottom property to 5.
<s:DataGroup id="dataGroup" top="5" bottom="5" minWidth="0" minHeight="0" horizontalCenter="0">
  1. Save the file and run the application.
  2. Mouse over an employee.

    Note that the rectangle you saw before is now gone.

  3. Return to the EmployeeItemRenderer.mxml file.
  4. Locate the states block.
  5. Below the normal State tag, add another instance of the State tag and add the name property with a value of hovered.
<s:states> <s:State name="normal"/> <s:State name="hovered"/> </s:states>
  1. Locate the BorderContainer block. This container draws the background for each item renderer and also displays the employee data.
  2. Below the BorderContainer instance, create a Rect instance with a height value of 100% and a width value of 100%. This will create a rectangle that will completely overlay the item renderer.
<s:Rect height="100%" width="100%"> </s:Rect>
  1. Within the Rect block, create a fill property tag block.
  2. Within the fill property, create a SolidColor instance and give it a color property with a value of #FFFFFF (white). This adds a highlight color when you hover over the item.
<s:fill> <s:SolidColor color="#FFFFFF"/> </s:fill>
  1. To the SolidColor instance, add the alpha property with a value of .2. This will make the highlight transparent.
<s:fill> <s:SolidColor color="#FFFFFF" alpha=".2"/> </s:fill>
  1. To the opening Rect tag, add the includeIn property with a value of hovered. Without the includeIn property, the rectangle would display all the time. Now you have made sure that it only displays in the hovered state.
<s:Rect height="100%" width="100%" includeIn="hovered">
  1. Locate the SolidColor instance within the fill block. To the color property add .hovered to make sure the color only appears in the hovered state.
<s:fill> <s:SolidColor color.hovered="#FFFFFF" alpha=".2"/> </s:fill>
  1. Save the file and run the application.
  2. Mouse over one of the employees.

You should see the employee is highlighted with a transparent white box (see Figure 7).

The employee data is highlighted when you mouse over it
Figure 7. The employee data is highlighted when you mouse over it.

In this exercise you changed the DataGroup container to a SkinnableDataContainer container so that you can apply a skin to it. In the next exercise you use Flash Builder to create a production build of the Flash application.

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.7: Creating a vertical title bar on a Panel container
  • Exercise 1.1: Setting up your project files
  • 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 4.1: Passing data to item renderers for display
  • Exercise 4.2: Displaying dynamic data in a custom item renderer
  • Exercise 4.3: Creating item renderers for Spark List components
  • Exercise 4.4: Using the Spark DataGrid control

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