In this exercise, you will create an item renderer component and use it to render the employee data (see Figure 1).

Figure 1. Review your task for this exercise.
In this exercise, you will learn how to:
In order to complete this tutorial, you need the following software and files:
In this section, you will use MXML to create a custom item renderer for a DataGroup container.
Declarations comment, locate the Declarations block.Within the Declarations block, notice the ArrayList tags and nested Object tags. This represents the data that is being used as the data provider.
<s:ArrayList id="employees">
<fx:Object firstName="Andrew"
lastName="Brilliam"
imageFile="images/abrilliam.jpg"/>
<fx:Object firstName="Ben"
lastName="Crater"
imageFile="images/bcrater.jpg"/>
<fx:Object firstName="David"
lastName="Avenon"
imageFile="images/davenon.jpg"/>
<fx:Object firstName="Annette"
lastName="Kotter"
imageFile="images/akotter.jpg"/>
<fx:Object firstName="Brian"
lastName="Minnows"
imageFile="images/bminnows.jpg"/>
<fx:Object firstName="Barry"
lastName="Kramson"
imageFile="images/bkramson.jpg"/>
</s:ArrayList>
DataGroup component.Within the DataGroup component tags, below the layout property tags, create an itemRenderer property tag set:
<s:DataGroup dataProvider="{employees}">
<s:layout>
<s:VerticalLayout/>
</s:layout>
<s:itemRenderer>
</s:itemRenderer>
</s:DataGroup>
Between the itemRenderer property tags, create a set of Component tags:
<s:itemRenderer>
<fx:Component>
</fx:Component>
</s:itemRenderer>
Between the Component tag set, create an ItemRenderer class tag set:
<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.
Between the ItemRenderer tags, create a states tag block:
<fx:Component>
<s:ItemRenderer>
<s:states>
</s:states>
</s:ItemRenderer>
</fx:Component>
Between the states tag block, create a State instance and assign normal as the name:
<s:states>
<s:State name="normal"/>
</s:states>
Between the ItemRenderer tags, below the states tag block, create an HGroup container tag block:
<s:ItemRenderer>
<s:states>
<s:State name="normal"/>
</s:states>
<s:HGroup>
</s:HGroup>
</s:ItemRenderer>
Between the ,HGroup tags, create an Image control:
<s:HGroup>
<mx:Image/>
</s:HGroup>
To the Image control, bind data.imageFile as the source:
<s:HGroup>
<mx:Image source="{data.imageFile}"/>
</s:HGroup>
Data for the current object that is being evaluated is referenced in the data property of the item renderer.
Within the HGroup tags, below the Image control, create a Label control:
<s:HGroup>
<mx:Image source="{data.imageFile}"/>
<s:Label/>
</s:HGroup>
To the Label control bind data.firstName as the text:
<s:HGroup>
<mx:Image source="{data.imageFile}"/>
<s:Label text="{data.firstName}"/>
</s:HGroup>
Within the HGroup tags, below the Label control, create a Label control and bind data.lastName as the text:
<s:HGroup>
<mx:Image source="{data.imageFile}"/>
<s:Label text="{data.firstName}"/>
<s:Label text="{data.lastName}"/>
</s:HGroup>
Save the file and run the application.
You should see the employee images and names displayed (see Figure 2).

Figure 2. Run the application to see the employee data displayed using the inline item renderer.
In this section, you will create a custom component to use as an item renderer.
From the Package Explorer view, right-click on the src folder and select New > Folder (see Figure 3).

Figure 3. Create a new folder.
In the New Folder dialog box, enter components for the Folder name (see Figure 4).

Figure 4. Name the folder components.
In the Package Explorer, right-click the components folder and select New > MXML Component (see Figure 5).

Figure 5. Create a new MXML component.
In the Based on dialog box, enter Item and select the ItemRenderer class (see Figure 6).

Figure 6. Select the ItemRenderer class.
In the New MXML Component dialog box, delete the Width and Height values (see Figure 7).

Figure 7. Fill in the New MXML Component dialog box.
Click Finish.
The EmployeeItemRenderer.mxml file will open in the editor.
Declarations tag block.DataGroup component.DataGroup component, cut the code within the ItemRenderer class tag block.Between the ItemRenderer tags, paste the copied code:
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">
<s:states>
<s:State name="normal"/>
</s:states>
<s:HGroup>
<mx:Image source="{data.imageFile}"/>
<s:Label text="{data.firstName}"/>
<s:Label text="{data.lastName}"/>
</s:HGroup>
</s:ItemRenderer>
DataGroup control.DataGroup component, delete the itemRenderer property tag block and its contents.To the DataGroup component, assign components.EmployeeItemRenderer as the itemRenderer:
<s:DataGroup dataProvider="{employeeList}"
itemRenderer="components.EmployeeItemRenderer">
<s:layout>
<s:VerticalLayout/>
</s:layout>
</s:DataGroup>
Save the file and run the application.
You should see the application appears as it did before (see Figure 8).

Figure 8. 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.
ItemRenderer class.Trilemetry, Inc is a development and education organization that implements a human-centered design approach to the creation of software and content. Their Adobe portfolio includes the Adobe ColdFusion Getting Started Experience, the Adobe Flex Getting Started Experience, the Flex in a Week video series, the official Adobe instructor-led training course Flex 3: Extending and Styling Components and more. They also create and support many Web applications from interactive Flash sites and corporate web sites to mission-critical business applications.