Requirements

Prerequisite knowledge Required products Exercise files User level

Flash Builder 4.7 Premium (Download trial)

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

 
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.