Beruflich Dokumente
Kultur Dokumente
html
In this exercise you will learn how to use the HTTPService object's result event to store data in a variable that is bound
to Flex controls.
Figure 1 shows employees listed in a DropDownList control at the top of the Company Vehicle Request Form. The data
for the selected user, which is retrieved from the database via an HTTPService object call, is bound to the office phone
number field.
Requirements
In order to complete this tutorial, you need the following software and files:
Flash Builder 4
Try (www.adobe.com/go/try_flashbuilder) Buy (www.adobe.com/go/flashbuilder_buy)
Exercise files:
1 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
Prerequisite knowledge:
Exercise 1.1: Setting up Flash Builder and your project files (www.adobe.comex1_01.html)
Exercise 2.1: Handling a user event (www.adobe.comex2_01.html)
In this section you will review the Company Vehicle Request Form that you built in Day 1 of this training series.
7. Return to Flash Builder and examine the code in the ex2_04_starter.mxml file. You should see the HTTPService
object that defines the XML file to be retrieved for the application data. The lastResult property of the service
object is bound to the DropDownList control and the two phone number fields.
Using the lastResult property of the service object is a very quick way to display data. However, if you want to
manipulate the data first, or place it into a reusable variable, you should use the result event to handle the data and then
bind it to the controls.
In this section, you define the result event handler for the HTTPService object.
2 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
The content assist tool is activated by placing your cursor inside the MXML tag (but outside any existing
properties) and pressing the spacebar. If you place each of your property/value pairs on a new line of code (see
Figure 3) and want to activate the content assist tool, simply, type Ctrl+spacebar. In either case, start typing the
name of the desired property or event, in this case result, to see that value selected.
Note: The lightening bolt icon indicates an event while the green circle indicates a property. The three square
blocks represent a style, and the light purple shape with the dots in the four corners represents an effect.
Figure 3. Use the content assist tool to generate the result event for the HTTPService object.
Using the content assist tool to generate the result event displays the Generate Result Handler option (see Figure
4).
4. Click the menu option or hit the Enter key to generate the result handler function.
Figure 4. Use the content assist tool to generate a result handler function for the HTTPService object.
import mx.rpc.events.ResultEvent;
...
protected function employeeService_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
}
Monitor the data request and retrieval using the Network Monitor
Before you handle the data in the result handler you just created, you will make sure that the request and response for
data were properly made. You will use the Network Monitor view to examine the request being made by Flash Builder
and the retrieved XML data from the server.
3 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
3. Click the Run button to run the application (see Figure 7).
4. Return to Flash Builder and double-click the Network Monitor view's tab to maximize the view.
5. Select the recording of the HTTPService object (see Figure 8).
6. On the right side, within the Response tab, expand the Response body tree to reveal the employee data (see
Figure 9).
4 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
Figure 9. Expand the Response body tree to reveal the employee data.
Examine the result event object using the Flash Builder Debugger
Now that you have verified that the server request and response have been properly sent and received, you will use the
Flash Builder Debugger to examine the data that is in your Flex application.
Figure 10. Place a breakpoint on the ending line of the employeeService_resultHandler() function.
3. Click the Debug button to debug the application (see Figure 11).
5 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
4. The browser will open and return you to Flash Builder. When you see the Confirm Perspective Switch dialog box
(see Figure 12), click the Yes button to switch to the Flash Builder Debug perspective.
Figure 12. Click the Yes button to switch to the Flash Builder Debug perspective.
Figure 13. Expand the result object to reveal the employees data.
6 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
Remember that the event object inside the employeeService_resultHandler() function is only available within
that function. To access the data outside the function, you will place the returned data into an ArrayCollection instance.
Figure 15. Use the content assist tool to assign a data type to the variable.
7 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
<mx:FormItem label="Employee:">
<s:DropDownList id="dropDownList"
labelField="LASTNAME"
dataProvider="{employees}"/>
</mx:FormItem>
8 of 9 16/04/2010 2:42 PM
Flex in a Week - Populating an ArrayCollection with retrieved data usin... http://www.adobe.com/devnet/flex/videotraining/exercises/ex2_04.html
In this tutorial you learned how to use the HTTPService object's result event to store data in a variable and how to map
the data to Flex controls using the variable.
What event can be used to handle the data being returned by an HTTPService object?
The result event.
What class of variable can be used to create a variable that can store data?
The ArrayCollection 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.
Copyright © 2010 Adobe Systems Incorporated. All rights reserved.
9 of 9 16/04/2010 2:42 PM