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 2.5: Retrieving and handling data with the RemoteObject object

by Trilemetry

Trilemetry
  • Trilemetry, Inc.

Content

  • Use the RemoteObject object
  • Make the RemoteObject object request
  • View the result data in the Network Monitor
  • Store the returned data in an application variable
  • Display the data in the application UI
  • Implement the fault event
  • Examine the fault event object
  • Display the fault data in an Alert dialog box

Created

2 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
  • Exercise 2.1: Handling a user event
  • Exercise 2.4: Populating an ArrayCollection with retrieved data

User level

Beginning

Required products

  • Flash Builder 4.7 Premium (Download trial)

Sample files

  • ex2_05_remote_starter.zip
  • ex2_05_remote_solution.zip

In the previous two exercises you used the HTTPService and WebService components to access dynamic server-side data. Both components return untyped data. If you want to work with typed data, use the RemoteObject component.

In this exercise you will use the RemoteObject object to retrieve the dynamic server-side data to populate the Employee DropDownList control in the Employee Portal: Vehicle Request application shown in Figure 1.

Preview the application.
Figure 1. Preview the application.

In this exercise you will learn how to:

  • Use the RemoteObject object
  • Make the RemoteObject request
  • View the returned data in the Network Monitor
  • Store the returned data in an application variable
  • Display the data in the UI
  • Implement the fault event
  • Examine the fault event object
  • Display the fault data in an Alert dialog box

Use the RemoteObject object

In this section you will use the RemoteObject component to retrieve the data for the Employee Portal: Vehicle Request application.

Note: In this exercise, you are using the remoting gateway for a ColdFusion server. However, you can use any server technology that supports binary AMF data. Some examples are BlazeDS for Java and the Zend Framework for PHP. Explore the mini Flex Developer Centers for PHP, Java, ColdFusion and .NET to learn more about Flex and those technologies.

  1. Download the ex2_05_remote_starter.zip file if you haven't already and extract the ex2_05_remote _starter.fxp to your computer.
  2. Open Flash Builder.
  3. Import the ex2_05_remote_starter.fxp file.
  4. Within the ex2_05_remote_starter project, open the ex2_05_remote_starter.mxml file.
  5. Locate the Declarations block.
  6. Between the Declarations tag set, create a RemoteObject instance:

<fx:Declarations> <s:RemoteObject/> </fx:Declarations>
  1. To the RemoteObject component instance, add the id property with a value of employeeService, the destination property with a value of ColdFusion, the source property with a value of f45iaw100.remoteData.employeeData, and the endpoint property with a value of http://adobetes.com/flex2gateway/.

    By setting the source property to f45iaw100.remoteData.employeeData, you are pointing to the ColdFusion component that the RemoteObject instance will use to query the database on the server. The endpoint value, http://adobetes.com/flex2gateway/, refers to the mapping used by the ColdFusion server to handle AMF/RemoteObject requests.

<s:RemoteObject id="employeeService" destination="ColdFusion" source="f45iaw100.remoteData.employeeData" endpoint="http://adobetes.com/flex2gateway/"/>
  1. Save the file.

Make the RemoteObject object request

In this section you will initialize the retrieval of data using the RemoteObject component.

  1. Within the opening Script block, locate the initApp() function.
  2. Within the function, call the employeeService.getEmployees() method.

    The getEmployees() method exists in the ColdFusion component and returns all of the employee information listed in the table on the server.

private function initApp():void { pickupDate.addEventListener(CalendarLayoutChangeEvent.CHANGE, dateChangeHandler); returnDate.addEventListener(CalendarLayoutChangeEvent.CHANGE, dateChangeHandler); employeeService.getEmployees(); }
  1. Save the file.

View the result data in the Network Monitor

Note: In order to complete this part of the exercise, you must have Flash Builder Premium Edition installed. If you have Flash Builder Standard Edition installed, skip this section and continue with the next section. If you want to download and install a trial version of Flash Builder Premium Edition, be sure to 1) back up your existing workspace and projects, 2) uninstall Flash Builder Standard Edition, and then 3) install the trial version of Flash Builder Premium Edition. To compare the Standard Edition with the Premium Edition, check out the Upgrade Details page.

In this section you will use the Network Monitor view to examine the data returned by the RemoteObject object.

  1. Open the Network Monitor view (see Figure 2).
Open the Network Monitor view.
Figure 2. Open the Network Monitor view.
  1. Click the Enable Monitor button (see Figure 3).
Turn on the Network Monitor.
Figure 3. Turn on the Network Monitor.
  1. Click the Run button to run the application.
  2. Return to Flash Builder and double-click the Network Monitor view's tab to maximize the view.
  3. Select the recording of the RemoteService (see Figure 4).
  4. Note: If the workspace you are using has multiple projects open, you may not see the recording in the Network Monitor. Close all other projects and enable the monitor again for your current project and make sure the message in the Network Monitor view reads, "Enabled for project 'ex2_05_remote_starter.'"

Select the RemoteService recording.
Figure 4. Select the RemoteService recording.
  1. On the right side, within the Response tab, expand the Response body tree to reveal the employee data.

    You should see that the data result is displayed in the Network Monitor as shown in Figure 5.

    Note: The data properties are all uppercase. ColdFusion returns properties in all upper case format by default. You need to adjust the Flex controls to be compatible with the data.

Expand the Response body tree to reveal the employee data.
Figure 5. Expand the Response body tree to reveal the employee data.
  1. Double-click the Network Monitor view's tab to minimize the view.

Store the returned data in an application variable

In this section you will store the retrieved data in an ArrayCollection variable named employees that is bound to the DropDownList control in the Employee Portal: Vehicle Request Form.

  1. Within the RemoteObject tag, use the content assist tool to generate the result event (see Figure 6).
Generate the result event.
Figure 6. Generate the result event.
  1. Within the content assist tool, double-click the Generate Result Handler option (see Figure 7).
Use the content assist tool to create a result handler function.
Figure 7. Use the content assist tool to create a result handler function.
  1. Within the Script block, locate the employeeService_resultHandler() function.
  2. Within the function, remove the commented code and set the value of the employees variable to the event.result property:
protected function employeeService_resultHandler(event:ResultEvent):void { employees = event.result; }
  1. Use the as operand to cast the event.result value to the ArrayCollection class.

    The result of the RemoteObject object is typed to the Object class by default. You must cast the result to the ArrayCollection class so that it can be used with the employees ArrayCollection variable.

protected function employeeService_resultHandler(event:ResultEvent):void { employees = event.result as ArrayCollection; }
  1. Save the file.

Display the data in the application UI

In this section you will adjust the application user interface to use the data returned by the service call.

  1. In the ex2_05_remote_starter.mxml file, within the Form container block, locate the FormItem container that nests the DropDownList control.
  2. Change the value of the DropDownList control's labelField property to LASTNAME.
<s:FormItem label="Employee:"> <s:DropDownList id="dropDownList" dataProvider="{employees}" labelField="LASTNAME"/> </s:FormItem>
  1. Locate the FormItem container that nests the TextInput control for the office phone number.
  2. Change the value the text property is being passed from the DropDownList control to dropDownList.selectedItem.PHONE:
<s:FormItem label="Office Phone:"> <s:TextInput id="phone" text="{dropDownList.selectedItem.PHONE}"/> </s:FormItem>
  1. Save the file.
  2. Run the application.
  3. Select an employee from the DropDownList control to see the Office Phone field populate (see Figure 8).
Select an employee from the DropDownList.
Figure 8. Select an employee from the DropDownList.

Implement the fault event

In this section, you will generate a fault event.

  1. Return to Flash Builder.
  2. Locate the RemoteObject object in the Declarations block.
  3. To the RemoteObject object, use the content assist tool to create a fault event.
  4. Still using content assist, choose the Generate Fault Handler option. This will create a fault event in the Script block.

Examine the fault event object

In this section, you will use the Flash Builder Debugger to view the information returned from the fault event.

  1. From the RemoteObject object's source property, remove the last character so that property will be invalid.
<s:RemoteObject id="employeeService" destination="ColdFusion" source="f45iaw100.remoteData.employeeDat" endpoint="http://adobetes.com/flex2gateway" result="employeeService_resultHandler(event)" fault="employeeService_faultHandler(event)"/>
  1. Within the Script block, locate the generated employeeService_faultHandler() function.
  2. Add a breakpoint to the same line as the closing brace of the employeeService_faultHandler() function (see Figure 9).
Place a breakpoint on the same line as the ending brace of the employeeService_faultHandler() function.
Figure 9. Place a breakpoint on the same line as the ending brace of the employeeService_faultHandler() function.
  1. Save the file.
  2. Click the Debug button.
  3. Click Yes when the Confirm Perspective Switch dialog box appears.
  4. Double-click the Variables tab to maximize the view.
  5. In the Variables view, expand the event object to reveal the fault event.

    Note the faultString property and value (see Figure 10).

View the debugging information for the fault event in the Variables view.
Figure 10. View the debugging information for the fault event in the Variables view.
  1. Double-click the Variables tab to minimize it.
  2. Click the Terminate button to end the debugging session.
  3. Return to the Flash perspective.

Display the fault data in an Alert dialog box

In this section, you will use the Alert class to create a pop-up dialog box to display fault data.

  1. Within the Script block, locate the employeeService_faultHandler() function.
  2. Within the function, use the show() method of the mx.controls.Alert class to display the event.fault.faultString value as text in an Alert pop-up. Make the title of the alert Fault Information.

    Within the Script block, note the import statement for the mx.controls.Alert class. If this import statement is not present, add it to your code to make the application work.

protected function employeeService_faultHandler(event:FaultEvent):void { Alert.show(event.fault.faultString,"Fault Information"); }
  1. Save the file and run the application.

    You will see the Alert dialog box display the fault event information (see Figure 11).

View the fault information within an Alert class dialog box.
Figure 11. View the fault information within an Alert class dialog box.

In this exercise you learned how to use a RemoteObject object to retrieve data from a remote ColdFusion server.

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