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 4.2: Displaying dynamic data in a custom item renderer

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Create an inline item renderer
  • Create an item renderer component class file

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 your project
  • Exercise 4.1: Passing data to item renderers for display

User level

Beginning

Required products

  • Flash Builder 4.7 Premium (Download trial)

Exercise files

  • ex4_02_starter.zip
  • ex4_02_solution.zip

In this exercise, you will create a custom item renderer and use it to display the employee data as shown in Figure 1.

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

In this exercise, you will learn how to:

  • Create an inline item renderer
  • Create an item renderer component class file

Create an inline item renderer

In this section, you will use MXML to create a custom item renderer for a DataGroup container.

  1. Download the ex4_02_starter.zip file provided in the Exercise files section and extract the ex4_02_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex4_02_starter.fxp file.
  4. Open ex4_02_starter.mxml.
  5. Below the Declarations comment, locate the Declarations block.
  6. Within the Declarations block, note the ArrayList tags and nested Object tags. This represents the data that is being used as the data provider.

    Note: You are using an ArrayList instance instead of an ArrayCollection instance for this example since the data will not be updated, and therefore, does not need the overhead of the bindings in the ArrayCollection class.

<s:ArrayList id="employeeList"> <fx:Object firstName="Samuel" lastName="Ang" imageFile="images/sang.jpg"/> <fx:Object firstName="Athena" lastName="Parker" imageFile="images/aparker.jpg"/> <fx:Object firstName="Saul" lastName="Tucker" imageFile="images/stucker.jpg"/> <fx:Object firstName="Alyssa" lastName="Le" imageFile="images/ale.jpg"/> </s:ArrayList>
  1. Locate the DataGroup component.
  2. Within the DataGroup component tags, below the layout property tags, create an itemRenderer property tag set.
<s:DataGroup dataProvider="{employeeList}"> <s:layout> <s:VerticalLayout/> </s:layout> <s:itemRenderer> </s:itemRenderer> </s:DataGroup>
  1. Between the itemRenderer property tags, create a set of Component tags.
<s:itemRenderer> <fx:Component> </fx:Component> </s:itemRenderer>
  1. Between the Component block, create an ItemRenderer class block.
<s:itemRenderer> <fx:Component> <s:ItemRenderer> </s:ItemRenderer> </fx:Component> </s:itemRenderer>

Remember that itemRenderer (lowercase i) is a property of the DataGroup class while ItemRenderer (capital I) is a class that you are instantiating.

  1. Between the ItemRenderer tags, create a states tag block.
<fx:Component> <s:ItemRenderer> <s:states> </s:states> </s:ItemRenderer> </fx:Component>
  1. Between the states block, create a State instance and assign normal as the name.
<s:states> <s:State name="normal"/> </s:states>
  1. Between the ItemRenderer tags, below the states tag block, create an BorderContainer block.
<s:ItemRenderer> <s:states> <s:State name="normal"/> </s:states> <s:BorderContainer> </s:BorderContainer> </s:ItemRenderer>
  1. To the opening BorderContainer tag, add the borderWeight property with a value of 2, the backgroundColor property with a value of #cccccc, the top property with a value of 5 and the height and width properties with a values of 100%.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" height="100%" width="100%"> </s:BorderContainer>
  1. Within the BorderContainer block, create a layout block.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" height="100%" width="100%"> <s:layout> </s:layout> </s:BorderContainer>
  1. Within the layout block, add the VerticalLayout tag.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" height="100%" width="100%"> <s:layout> <s:VerticalLayout/> </s:layout> </s:BorderContainer>
  1. Within the BorderContainer block, below the layout block, create an Label control.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" height="100%" width="100%"> <s:layout> <s:VerticalLayout/> </s:layout> <s:Label /> </s:BorderContainer>
  1. To the Label control, add the text property and bind data.firstName and data.lastName as the value.
<s:Label text="{data.firstName} {data.lastName}"/>

Data for the current object that is being evaluated is referenced in the data property of the item renderer.

  1. Within the BorderContainer block, below the Label control, create an BitmapImage control.
... <s:Label text="{data.firstName} {data.lastName}"/> <s:BitmapImage /> </s:BorderContainer>
  1. To the BitmapImage control, add the source property with a bound value of data.imageFile.
<s:BitmapImage source="{data.imageFile}"/>
  1. Save the file and run the application.

    You should see the employee images and names displayed with a border and background color, as shown in Figure 2. Note, however that the employees are not centered within the item renderer.

Run the application to see the employee data displayed using the inline item renderer.
Figure 2. Run the application to see the employee data displayed using the inline item renderer.
  1. Return to the ex4_02_starter.mxml starter file in Flash Builder.
  2. Locate the BorderContainer block.
  3. Within the layout block, to the VerticalLayout tag, add the horizontalAlign property with a value of center.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5" height="100%" width="100%"> <s:layout> <s:VerticalLayout horizontalAlign="center"/> </s:layout> <s:Label text="{data.firstName} {data.lastName}"/> <s:BitmapImage source="{data.imageFile}"/> </s:BorderContainer>
  1. Save the file and run the application.

    You should see the employee name and image are now centered horizontally in each item renderer (see Figure 3).

Center the employee name and image horizontally in the item renderer.
Figure 3. Center the employee name and image horizontally in the item renderer.
  1. Return to the ex4_02_starter.mxml in Flash Builder.
  2. Within BorderContainer block's layout block, to the VerticalLayout tag, add the verticalAlign property with a value of middle.
<s:BorderContainer borderWeight="2" backgroundColor="#cccccc" top="5"height="100%" width="100%"> <s:layout> <s:VerticalLayout horizontalAlign="center" verticalAlign="middle"/> </s:layout> <s:Label text="{data.firstName} {data.lastName}"/> <s:BitmapImage source="{data.imageFile}"/> </s:BorderContainer>
  1. Save the file and run the application.
  2. You should see the employee name and image are now vertically and horizontally centered in the item renderer (see Figure 4).

Run the application to see the employee information is centered within the item renderer.
Figure 4. Run the application to see the employee information is centered within the item renderer.

Create an item renderer component class file

In this section, you will create a custom component to use as an item renderer.

  1. Return to Flash Builder.
  2. Within the Package Explorer, right-click the src folder and select New > Item Renderer (see Figure 5).
Create a new Item Renderer.
Figure 5. Create a new Item Renderer.
  1. Within the New Item Renderer dialog box, for the Package type components and for the Name type EmployeeItemRenderer.

Your New Item Renderer dialog box should appear as shown in Figure 6.

Fill in the New Item Renderer dialog box.
Figure 6. Fill in the New Item Renderer dialog box.
  1. Click Finish.

    The EmployeeItemRenderer.mxml file will open in the editor.

  2. Delete the Label control that was generated with the file.
  3. Switch to the ex4_02_starter.mxml file.
  4. Locate the DataGroup component.
  5. Within the DataGroup component, cut the code between the ItemRenderer tags.
  6. Switch the EmployeeItemRenderer.mxml file.
  7. Paste the copied code between the ItemRenderer tags..
  8. Save the file.
  9. Return to the ex4_02_starter.mxml file.
  10. From within the DataGroup component, delete the itemRenderer block and its contents.
  11. To the DataGroup component, add the itemRenderer property with a value of components.EmployeeItemRenderer.
<s:DataGroup dataProvider="{employeeList}" itemRenderer="components.EmployeeItemRenderer"> <s:layout> <s:VerticalLayout/> </s:layout> </s:DataGroup>
  1. Save the file and run the application.

    You should see the application appears as it did before, as shown in Figure 7.

Run the application to see it has not changed.
Figure 7. Run the application to see it has not changed.

In this exercise, you learned how to create a custom item renderer component for a group of data. In the next exercise you will apply the item renderer component created in this exercise to a Spark List 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.10: Creating a production build
  • Exercise 5.8: Animating Button components
  • 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

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