Adobe is changing the world through digital experiences. Our creative, marketing and document solutions empower everyone — from emerging artists to global brands — to bring digital creations to life and deliver them to the right person
at the right moment for the best results.

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.

User level

Required products

Sample files

When you retrieved data from an XML file in previous exercises, the Flex framework has automatically converted that data into an ArrayCollection instance of generic objects.

In this exercise you will convert this ArrayCollection of generic objects into an ArrayCollection of typed data. You will use the Employee class, which was created in Exercise 2.7 (Creating an ActionScript class and instances), as an ActionScript value object class. Its properties will correspond to the values in the XML data.

Within the New ActionScript class dialog box, for the Package type valueObjects and for the Name type Employee (see Figure 2).

Figure 2. Name the class Employee.

Click Finish.

You should see the Employee.as file open in the Editor view.

Within the class declaration function, create the following public variables all data typed to the String class.

public class Employee
{
public var firstName:String;
public var lastName:String;
public var id:String;
public var title:String;
public var email:String;
public var managerID:String;
public var department:String;
public var location:String;
public var phone:String;
public var directDial:String;
public var deskLocation:String;
public var city:String;
public var state:String;
public var countryCode:String;
public var hireDate:String;
public var evaluation:String;
public var postalCode:String;
}

Save the file.

Create value object instances

In this section you will create a local variable, named employeeData, to store the data returned by the HTTPService object. You will then loop over the employeeData instance to access each generic object to create an equivalent value object, which you will then place into the employees ArrayCollection instance.

Return to Flash Builder and within the Package Explorer view, from the default package, open the ex2_08_starter.mxml file.

Within the Script block, locate the employeeService_resultHandler() function.

Delete everything within the function and create a local variable named employeeData data typed to the ArrayCollection class.

Modify the template generated for the for each loop by changing i to create an iterant named emp and change int so that it is data typed to the Object class. This parameter will be used to store the value being looped over in the data.

Note that the in operand automatically specifies the employeeDataArrayCollection variable as the data to loop over.

for each(var emp:Object in employeeData)
{
}

Within the for each loop, to the employee variable, create a new instance of the Employee value object class:

On each iteration of the loop, a new instance of the Employee class is created with data provided by the returned data from the HTTPService call. The loop will continue to run until all return data has been evaluated. Currently each of these employee instances is only available in this function. Later, you will populate the employees ArrayCollection variable with the typed data.

Save the file.

View the value object in the Debugger

In this section you will use the Flash Builder Debugger to view the first generated employee instance.

Within the Script block, locate the closing brace of the employeeService_resultHandler() function and double-click next to the line number to set a breakpoint (see Figure 4).

Figure 4. Add a breakpoint to the closing line of the employeeService_resultHanlder() function.

Click the Debug button.

When you see the Confirm Perspective Switch dialog box, click the Yes button (see Figure 5).

Figure 5. Click the Yes button to switch perspectives.

Within the Flash Debug perspective, double-click the Variables view to maximize it.

Expand the employee value object variable to reveal its properties.

This is only one of the value object instances that are created in the loop. Currently, each new loop iteration overwrites the previous instance with a new instance. In the next section, you will populate the employees ArrayCollection variable with the data before it is overwritten.

Within the employees node, open each object node to see they have different property values.

Double-click the Variables tab to minimize the view.

Click the Terminate button to stop the debugging session.

Click the Run button to run the application.

Open the DropDownList control.

You should see the DropDownList control is populated with employees (see Figure 9).

Figure 9. Open the DropDownList control to see the control is populated with employees.

In this exercise you learned how to create a data model using typed data. In the next exercise you will use the Flash Builder Data Services wizard to connect to a web service and generate ActionScript value object classes.