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.1: Passing data to item renderers for display

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use the DefaultItemRenderer class
  • Use the DefaultComplexItemRenderer class
  • Use an item renderer function
  • Change the display order of the data objects
  • Use the ClassFactory class to define an item renderer

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

User level

Beginning

Required products

  • Flash Builder 4.7 Premium (Download trial)

Exercise files

  • ex4_01_starter.zip
  • ex4_01_solution.zip

In this exercise you will render data in a DataGroup container. You will first do so with simple string data and then UI elements. Lastly, you will display both strings and images in an item renderer that employs a function and conditional evaluation (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 the DefaultItemRenderer class
  • Use the DefaultComplexItemRenderer class
  • Use an item renderer function
  • Change the display order of the data objects
  • Use the ClassFactory class to define an item renderer

Use the DefaultItemRenderer class

In this section, you will use the DefaultItemRenderer class to render a group of data.

  1. Download the ex4_01_starter.zip file that accompanies this tutorial and extract the file ex4_01_starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex4_01_starter.fxp file.
  4. Open ex4_01_starter.mxml.
  5. Locate the Declarations comment.
  6. Within the Declarations tag block, create a set of ArrayList tags:
<fx:Declarations> <s:ArrayList> </s:ArrayList> </fx:Declarations>
  1. To the ArrayList collection, add the id property with a value of employeeList:
<s:ArrayList id="employeeList"> </s:ArrayList>
  1. Between the ArrayList tags, create a String block:
<s:ArrayList id="employeeList"> <fx:String></fx:String> </s:ArrayList>
  1. Type Samuel Ang for the value of the String class:
<s:ArrayList id="employeeList"> <fx:String>Samuel Ang</fx:String> </s:ArrayList>
  1. Copy the String tags and paste three more instances within the ArrayList collection below the first String class instance:
<s:ArrayList id="employeeList"> <fx:String>Samuel Ang</fx:String> <fx:String>Samuel Ang</fx:String> <fx:String>Samuel Ang</fx:String> <fx:String>Samuel Ang</fx:String> </s:ArrayList>
  1. Reassign the pasted String instance values to the following employee names:Athena Parker, Saul Tucker, and Alyssa Le.
<s:ArrayList id="employeeList"> <fx:String>Samuel Ang</fx:String> <fx:String>Athena Parker</fx:String> <fx:String>Saul Tucker</fx:String> <fx:String>Alyssa Le</fx:String> </s:ArrayList>
  1. Locate the Label control below the UI components comment:
  2. Below the Label control, create a DataGroup component tag block:
<s:Label width="440" height="40" text="Employee Portal: Employee Directory" styleName="titleHeader" /> <s:DataGroup> </s:DataGroup>
  1. To the DataGroup component, add the dataProvider property and bind the value to the employeeList ArrayList collection.:
<s:DataGroup dataProvider="{employeeList}"> </s:DataGroup>
  1. Save the file.
  2. Run the application.

    You should see an ActionScript error message, "Could not create an item renderer for Samuel Ang" (see Figure 2).

Run the application to see the ActionScript error message.
Figure 2. Run the application to see the ActionScript error message.
  1. Return to Flash Builder.
  2. To the DataGroup component, assign spark.skins.spark.DefaultItemRenderer as the itemRenderer class:
<s:DataGroup dataProvider="{employeeList}" itemRenderer="spark.skins.spark.DefaultItemRenderer"> </s:DataGroup>
  1. Save the file and run the application.

    Note that the employee names in the ArrayList collection are all displayed in the same place (see Figure 3). All the employee names have been processed, but because no layout has been assigned to the DataGroup component, each employee name has been assigned the default x and y values of zero, which causes them to be stacked on top of each other.

Run the application to see the data displayed.
Figure 3. Run the application to see the data displayed.
  1. Return to Flash Builder.
  2. Between the DataGroup tags, create a set of layout property tags and assign a VerticalLayout instance:
<s:DataGroup dataProvider="{employeeList}" itemRenderer="spark.skins.spark.DefaultItemRenderer"> <s:layout> <s:VerticalLayout/> </s:layout> </s:DataGroup>
  1. To the VerticalLayout tag, add the paddingLeft and the paddingTop properties, both with a value of 25.
<s:layout> <s:VerticalLayout paddingLeft="25" paddingTop="25"/> </s:layout>
  1. Save the file and run the application.

    You should see the employee names displayed vertically below the header text (see Figure 4).

Run the application to see the employees displayed vertically below the header text.
Figure 4. Run the application to see the employees displayed vertically below the header text.

Use the DefaultComplexItemRenderer class

In this section, you will use the DefaultComplexItemRenderer class to render employee image data.

  1. Return to Flash Builder.
  2. Locate the ArrayList collection nested within the Declarations tag block.
  3. Below the last String instance, create a BitmapImage control:
... <s:ArrayList id="employeeList"> <fx:String>Samuel Ang</fx:String> <fx:String>Athena Parker</fx:String> <fx:String>Saul Tucker</fx:String> <fx:String>Alyssa Le</fx:String> <s:BitmapImage/> </s:ArrayList> ...
  1. To the BitmapImage control, add the source property with a value of images/sang.jpg.
... <fx:String>Alyssa Le</fx:String> <s:BitmapImage source="images/sang.jpg"/> </s:ArrayList> ...
  1. Within the ArrayList collection, copy the BitmapImage control and paste three instances below the first:
... <s:BitmapImage source="images/sang.jpg"/> <s:BitmapImage source="images/sang.jpg"/> <s:BitmapImage source="images/sang.jpg"/> <s:BitmapImage source="images/sang.jpg"/> </s:ArrayList> ...
  1. Reassign the source properties of the added BitmapImage controls to use the following images from the images directory: aparker.jpg, stucker.jpg, and ale.jpg.
... <s:BitmapImage source="images/sang.jpg"/> <s:BitmapImage source="images/aparker.jpg"/> <s:BitmapImage source="images/stucker.jpg"/> <s:BitmapImage source="images/ale.jpg"/> </s:ArrayList> ...
  1. Locate the DataGroup component.
  2. To the DataGroup component, reassign spark.skins.spark.DefaultComplexItemRenderer as the itemRenderer:
<s:DataGroup dataProvider="{employeeList}" itemRenderer="spark.skins.spark.DefaultComplexItemRenderer"> <s:layout> <s:VerticalLayout/> </s:layout> </s:DataGroup>
  1. Save the file and run the application.

    You should see the employee images displayed vertically below the header (see Figure 5). Note that the employee names are not displayed.

Run the application to see the employee images displayed, but not the employee names.
Figure 5. Run the application to see the employee images displayed, but not the employee names.

Use an item renderer function

In this section, you will use a function to determine the correct item renderer class to use to render the data.

  1. Return to Flash Builder.
  2. Locate the DataGroup component.
  3. From the DataGroup component, remove the itemRenderer property and value.
  4. To the DataGroup component, add the itemRendererFunction property with a value of rendererFunction:
<s:DataGroup dataProvider="{employeeList}" itemRendererFunction="rendererFunction"> <s:layout> <s:VerticalLayout/> </s:layout> </s:DataGroup>
You will now create the function that tests what type of data is being rendered for each element in the ArrayList collection. Remember that this function is called multiple times, once for every element of data.
  1. Locate the Script comment.
  2. Below the comment, create a Script block:
<!-- Script ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --> <fx:Script> <![CDATA[ ]]> </fx:Script>
  1. Within the Script block, create a private function named rendererFunction that returns information data typed to the ClassFactory class:
private function rendererFunction():ClassFactory { }
  1. For the rendererFunction() function, assign one parameter named item and data type it to the Object class:
private function rendererFunction (item:Object):ClassFactory { }

The item argument represents the data element that is currently being evaluated by this rendererFunction() method. If the data is a string, then you will use the DefaultItemRenderer class to render it. If the data is a UI element, then you will use the DefaultComplexItemRenderer to render it.

  1. Within the rendererFunction() function, type if, invoke content assist and select the if statement template to create a condition statement that evaluates if the item parameter value is of the String data type:
private function rendererFunction(item:Object):ClassFactory { if(item is String) { } }
  1. Within the if statement, use the return statement to create a new instance of the ClassFactory class and render the data using the DefautItemRenderer class. Use the content assist tool to return the DefaultItemRenderer class and note that the corresponding import statement is generated within the Script block:
import spark.skins.spark.DefaultItemRenderer; if(item is String) { return new ClassFactory(DefaultItemRenderer); }
  1. Below the if statement, create an else statement:
if(item is String) { return new ClassFactory(DefaultItemRenderer); } else { }
  1. Within the else statement, use the return statement to return a new instance of the ClassFactory class and render the data using the DefaultComplexItemRenderer class. Use the content assist tool to select the DefaultComplexItemRenderer as the class to be returned and note that the corresponding import statement is generated within the Script block:
import spark.skins.spark.DefaultComplexItemRenderer; if(item is String) { return new ClassFactory(DefaultItemRenderer); } else { return new ClassFactory(DefaultComplexItemRenderer); }
  1. Save the file and run the application.

    You should see the employee names and images are displayed in the order they are listed within the ArrayList collection (see Figure 6).

Run the application to see all the data displayed.
Figure 6. Run the application to see all the data displayed.

Change the display order of the data objects

In this section, you will arrange the data objects in the ArrayList collection so that the employee names and images are displayed relative to each other.

  1. Return to Flash Builder.
  2. Within the ArrayList collection nested within the Declarations block.
  3. Within the ArrayList collection, move the BitmapImage controls so they are located below the respective String tag.
<s:ArrayList id="employeeList"> <fx:String>Samuel Ang</fx:String> <s:BitmapImage source="images/sang.jpg"/> <fx:String>Athena Parker</fx:String> <s:BitmapImage source="images/aparker.jpg"/> <fx:String>Saul Tucker</fx:String> <s:BitmapImage source="images/stucker.jpg"/> <fx:String>Alyssa Le</fx:String> <s:BitmapImage source="images/ale.jpg"/> </s:ArrayList>
  1. Save the file and run the application.

    You should see the employees names are displayed above their picture (see Figure 7).

Run the application to see the employee names displayed above their images.
Figure 7. Run the application to see the employee names displayed above their images.

Use the ClassFactory class to define an item renderer

In this section, you will use the ClassFactory class to instantiate a custom item renderer. You will learn more about item renderers in the next video and associated exercise.

  1. Return to Flash Builder and open the NameDisplay.mxml file from the components package.
  2. Review the contents of the file. You will use the NameDisplay.mxml file to make a custom item renderer.
  3. Open the ex4_01_starter.mxml file.
  4. Locate the rendererFunction() method in the Script block.
  5. In the if statement within the function, change the return operation so that it returns a new instance of the ClassFactory class and renders the data using the NameDisplay class. Use the content assist tool (CTRL+Space) to select the NameDisplay as the class to be returned and note that the corresponding import statement is generated within the Script block.
if(item is String) { return new ClassFactory(NameDisplay); }
  1. Save the file and run the application.

    You should see the data from the custom item renderer displayed (see Figure 8).

View the application and the custom item renderer.
Figure 8. View the application and the custom item renderer.

In this exercise you learned how to use the DefaultItemRenderer and DefaultComplexItemRenderer classes to render data for a DataGroup component. You also learned how to create a function to render data. In the next exercise you will create a custom item renderer and use it to display employee data.

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