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 4.3: Creating item renderers for Spark List components

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Apply the Spark item renderer to the Spark List control
  • Apply the Spark item renderer to the Spark ComboBox control

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 your project
  • Exercise 4.1: Passing data to item renderers for display
  • Exercise 4.2: Displaying dynamic data in a custom item renderer

User level

Beginning

Required products

  • Flash Builder 4.5 Premium (Download trial)

Exercise files

  • ex4_03_starter.zip
  • ex4_03_solution.zip

In this exercise you will apply the item renderer component created in Exercise 4.2: Displaying dynamic data in a custom item renderer to a Spark List control (see Figure 1). You will also use the same item renderer with a Spark ComboBox control.

This is another example of the flexibility of the Spark component architecture.

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

In this exercise, you will learn how to:

  • Apply a Spark item renderer to the Spark List control
  • Apply the Spark item renderer to the Spark ComboBox control

Apply the Spark item renderer to the Spark List control

In this section, you will use the item renderer created in the previous exercise to render a Spark List control.

  1. Download the ex4_03_starter.zip file provided in the Exercise files section and extract the ex4_03_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex4_03_starter.fxp file.
  4. Open ex4_03_starter.mxml.
  5. Locate the DataGroup control.
  6. Replace the opening and closing DataGroup tags with List control tags.
<s:List dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer"> <s:layout> <s:VerticalLayout/> </s:layout> </s:List>
  1. Save the file and run the application.

    You should see the black border of the List control surrounding the employees (see Figure 2).

Run the application to see the employees rendered in the List control.
Figure 2. Run the application to see the employees rendered in the List control.

Apply the Spark item renderer to the Spark ComboBox control

In this section you will use the item renderer to display the employees in a Spark ComboBox control.

  1. Return to the ex4_03_starter.mxml file in Flash Builder.
  2. Locate the List block.
  3. Replace the opening and closing List tags with ComboBox control tags.
<s:ComboBox dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer"> <s:layout> <s:VerticalLayout/> </s:layout> </s:ComboBox>
  1. Save the file and run the application.
  2. Open the ComboBox control.

    You should see the employees displayed with the item renderer, as shown in Figure 3.

Open the ComboBox control to view the employees.
Figure 3. Open the ComboBox control to view the employees.
  1. Select an employee from the ComboBox control.

    You should see the string [object Object] in the ComboBox control, as shown in Figure 4. This means that you need to define the property to display in the ComboBox control.

Select an employee to see the string displayed in the ComboBox control.
Figure 4. Select an employee to see the string displayed in the ComboBox control.
  1. Return to the ex4_03_starter.mxml file in Flash Builder.
  2. To the ComboBox control, add the labelField property with a value of lastName and add the width property with a value of 125.
<s:ComboBox dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer" labelField="lastName" width="125"> <s:layout> <s:VerticalLayout/> </s:layout> </s:ComboBox>
  1. Save the file and run the application.
  2. Select an employee from the ComboBox control.

    You should see the employee's last name displayed in the ComboBox control, as shown in Figure 5. Notice that the employee data is not centered within the ComboBox control.

Select an employee to see the last name displayed in the ComboBox control.
Figure 5. Select an employee to see the last name displayed in the ComboBox control.
  1. Return to Flash Builder.
  2. From the Package Explorer view, locate the components folder and open the EmployeeItemRenderer.mxml file.
  3. Within the opening BorderContainer tag, add the bottom, left, and right property with a value of 5.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" bottom="5" left="5" right="5" height="100%" width="100%"/>
  1. Save the file.
  2. Run the application.
  3. Click the drop-down list.

    Notice the employee data is now centered within the ComboBox control (see Figure 6).

The employee data is centered in the ComboBox control
Figure 6. The employee data is centered in the ComboBox control.

In this exercise you learned how to use an item renderer with a Spark List control and a Spark ComboBox control.

 

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.9: Skinning the SkinnableDataContainer container
  • Exercise 5.10: Creating a production build
  • Exercise 5.7: Creating a vertical title bar on a Panel container
  • Exercise 1.1: Setting up your project files
  • Exercise 1.6: Creating MXML custom components with ActionScript properties
  • Exercise 2.1: Handling a user event
  • Exercise 2.2: Using the event object
  • Exercise 2.3: Using the addEventListener() method
  • Exercise 2.4: Populating an ArrayCollection with retrieved data using the result event
  • Exercise 4.5: Creating and using item renderers and item editors

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