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.6: Creating custom skin properties

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Create a custom skin property
  • Pass a value to a custom skin property

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

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Sample files

  • ex5_06_starter.zip
  • ex5_06_solution.zip

In this exercise you will create a custom skin property and reuse it to style a Panel container skin with differently colored highlights (see Figure 1).

This is the finished application.
Figure 1. Review your task for this exercise.

In this exercise, you will learn how to:

  • Create a custom skin property
  • Pass a value to a custom skin property

Create a custom skin property

In this section, you will change the color of the title bar for each of the Panel containers within the Employee Portal application.

  1. Download the ex5_06_starter.zip file if you haven't done so already and extract the ex5_06_starter.fxp file to your computer.
  2. Open Flash Builder.
  3. Import the ex5_06_starter.fxp file.
  4. Open the ex5_06_starter.mxml file.
  5. Locate the four panel instances in the components namespace and comment them out.
  6. Save the file.
  7. In the Package Explorer, right-click the components package and select New > MXML Component.
  8. Name the MXML component EmployeePortalPanel.
  9. Click the Browse button next to the Based on field.
  10. In the Based on dialog box, type Panel and select the Spark Panel container (see Figure 2).
Base the new MXML component on the Spark Panel container.
Figure 2. Base the new MXML component on the Spark Panel container.
  1. Click OK.
  2. In the New MXML Component dialog box, type 250 for the Width value and 475 for the Height value (see Figure 3).
Name the component EmployeePortalPanel, base it on the Spark Panel container, and replace the Width and Height values.
Figure 3. Name the component EmployeePortalPanel, base it on the Spark Panel container, and replace the Width and Height values.
  1. Click Finish.

    The EmployePortalPanel.mxml file will open in the Flash Builder Editor view.

  2. Delete the Declaration tag block and create a Script block.
  3. Within the Script block, type panelTitleColor and press CTRL+1 to invoke the quick assist tool. Select the Create instance variable option. This will create a private variable named panelTitleColor data typed to the Object class.
  4. Change the variable's access modifier to public and modify the data type to the uint class.
<fx:Script> <![CDATA[ public var panelTitleColor:uint; ]]> </fx:Script>
  1. Save the file.
  2. Open the ex5_06_starter.mxml file.
  3. After the four Panel instances that you commented out, create an EmployeePortalPanel component tag block.
  4. To the EmployeePortalPanel component opening tag, assign the title property value to EMPLOYEE OF THE MONTH.
  5. Use the content assist tool to add the panelTitleColor property to the EmployeePortalPanel tag and give it a value of #64BC48 (green).
  6. Within the EmployeePortalPanel component tag set, add an instance of the EmployeeOfTheMonth component.
<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH" panelTitleColor="#64BC48"> <components:EmployeeOfTheMonth/> </components:EmployeePortalPanel>
  1. Save the file and run the application.

    You will see only one panel that is not properly positioned. You will fix that later. However, note that there are two panel title areas for the Employee of the Month panel (see Figure 4). This occurs because each component is based on the Panel container.

There are two panels for the Employee of the Month panel.
Figure 4. There are two panels for the Employee of the Month panel.
  1. Return to Flash Builder and open the EmployeeOfTheMonth.mxml component.
  2. Change the component's Panel container to a Group container.
  3. In the opening Group container tag, reassign the width and height properties to a value of 100%.
<s:Group xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s="library://ns.adobe.com/flex/spark" width="100%" height="100%">
  1. Save the file.
  2. Repeat steps 23-26 for the Cafeteria.mxml and MonthlyEvents.mxml components.
  3. Return to the ex5_06_starter file.
  4. From the commented EmployeeOfTheMonth component instance, copy the x, y, and skinClass properties and their values and paste them into the opening EmployeePortalPanel component instance.
  5. To the opening EmployeePortalPanel component instance, add the height property with a value of 295.
<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH" panelTitleColor="#64BC48" x="0" y="95" skinClass="skins.PanelContainerSkin" height="295">
  1. Save the file and run the application.

    You should see that only the Employee of the Month panel is displayed and the color block of the panel's title bar has not changed (see Figure 5).

Only the Employee of the Month panel is displayed.
Figure 5. Only the Employee of the Month panel is displayed.

Pass a value to a custom skin property

In this section you will create a function to handle the passing of the panelTitleColor property value from the main application file to the custom component.

  1. Return to Flash Builder and open the PanelContainerSkin.mxml file from the skins package.
  2. Locate the nested fill property within the Rect tag block that follows the PanelSkin instance.
  3. From the nested SolidColor tag, remove the color property value:
<s:fill> <s:SolidColor/> </s:fill>
  1. To the SolidColor tag, assign the id property to headerSkinColor:
<s:fill> <s:SolidColor id="headerSkinColor"/> </s:fill>
  1. Locate the MetaData tags.
  2. Within the HostComponent() function, change the value to reference the EmployeePortalPanel component:
<fx:Metadata> [HostComponent("components.EmployeePortalPanel")] </fx:Metadata>
  1. Locate the Script comment and add a Script block below it:
<!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <fx:Script> <![CDATA[ ]]> </fx:Script> ...
  1. Within the Script block, create a private function named initTitleSkin that returns a void data type:
<fx:Script> <![CDATA[ private function initTitleSkin():void { } ]]> </fx:Script>
  1. Within the initTitleSkin() function, assign the color property of the headerSkinColor SolidColor fill to the hostComponent.panelTitleColor property value:
private function initTitleSkin():void { headerSkinColor.color = hostComponent.panelTitleColor; }
  1. To the opening SparkSkin tag, assign the creationComplete property value to call the initTitleSkin() function:
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="initTitleSkin()">
  1. Save the file and run the application.

    You should see that the color block in the Employee of the Month panel is now green (see Figure 6).

Change the Employee of the Month Panel container's header color block to green.
Figure 6. Change the Employee of the Month Panel container's header color block to green.
  1. Return to the ex5_06_starter.mxml file in Flash Builder.
  2. Copy the EmployeePortalPanel component and paste two instances below the first.
<components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH" panelTitleColor="#64BC48" x="0" y="95" skinClass="skins.PanelContainerSkin" height="295"> <components:EmployeeOfTheMonth/> </components:EmployeePortalPanel> <components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH" panelTitleColor="#64BC48" x="0" y="95" skinClass="skins.PanelContainerSkin" height="295"> <components:EmployeeOfTheMonth/> </components:EmployeePortalPanel> <components:EmployeePortalPanel title="EMPLOYEE OF THE MONTH" panelTitleColor="#64BC48" x="0" y="95" skinClass="skins.PanelContainerSkin" height="295"> <components:EmployeeOfTheMonth/> </components:EmployeePortalPanel>
  1. To the second instance of the EmployeePortalPanel component, reassign the title property to CAFETERIA SPECIAL, the panelTitleColor property value to #F05123 (orange), and the x property value to 275.
  2. Remove the height property and and change the nested component to the Cafeteria component.
<components:EmployeePortalPanel title="CAFETERIA SPECIAL" panelTitleColor="#F05123" x="275" y="95" skinClass="skins.PanelContainerSkin"> <components:Cafeteria/> </components:EmployeePortalPanel>
  1. To the third instance of the EmployeePortalPanel component, reassign the title property to MONTHLY EVENTS, the panelTitleColor property value to #0D86B8 (blue), and the x property value to 550.
  2. Remove the height property and change the nested component to the MonthlyEvents component.
<components:EmployeePortalPanel title="MONTHLY EVENTS" panelTitleColor="#0D86B8" x="550" y="95" skinClass="skins.PanelContainerSkin"> <components:MonthlyEvents/> </components:EmployeePortalPanel>
  1. Locate the commented EmployeeDirectory component instance.
  2. Copy the EmployeeDirectory component instance and paste it below the third instance of the EmployeePortalPanel component.

    Since the EmployeeDirectory component does not use the PanelContainerSkin, you do not need to nest it within an EmployeePortalPanel component instance.

  3. Save the file and run the application.

    You should see the Employee of the Month, Cafeteria Special, and MonthlyEvents panels have different colored headers (see Figure 7). Also note that the text in the Monthly Events panel is blue.

Pass the EmployeePortalPanel component the header color from the main application.
Figure 7. Pass the EmployeePortalPanel component the header color from the main application.
  1. Return to Flash Builder and open the ex5_06_starter.css file.
  2. Locate the MonthlyEvents selector and comment out the color property.
  3. Save the file and run the application.

You should see that the text within the Monthly Events panel is now black (see Figure 8).

The text in the Monthly Events panel is black.
Figure 8. The text in the Monthly Events panel is black.

In this exercise you created a custom skin property and reused it to style a Panel container skin with different colored highlights. In the next exercise you will learn how to use a skin to make the Panel container title bar vertical.

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 4.6: Navigating using navigator containers
  • Exercise 4.7: Creating and navigating application states
  • Exercise 4.8: Creating a scalable user interface
  • Exercise 4.9: Animating components with effects
  • Exercise 3.5: Using formatters
  • Exercise 3.6: Validating form data
  • Exercise 3.7: Using two-way binding
  • Exercise 3.8: Creating a master/detail interface with a wizard
  • Exercise 4.10: Applying transitions to view states
  • Exercise 4.1: Passing data to item renderers for display

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