Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders 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
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Data-centric development with Flash Builder 4

by Sunil Bannur

Sunil Bannur
  • Adobe

Modified

8 March 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
CFC data management data-centric development Flash Builder

Requirements

Prerequisite knowledge

Previous experience with Flex Builder is helpful but not necessary. Familiarity with a server side technology such as ColdFusion, Java, or PHP is needed.

User Level:

All

Required products

  • Flex Builder (Download trial)

Adobe Flash Builder 4 opens new opportunities for Flex developers—including newcomers and seasoned pros—to build data-centric rich Internet applications. The combination of professional tools, an open source framework, and ubiquitous clients that make up the Flash platform allows you to deliver amazing expressive content and applications.

Most applications, however, also rely on services that reside outside of the platform. Perhaps your application provides reporting and data visualization for information stored in a corporate database. Or perhaps your rich e-commerce application needs to integrate with your existing order management system or a third party payment service. Application functionality enabling everything as simple as sending e-mail and querying databases through integration with cloud hosted services and third party APIs require you to connect to servers or services.

With past releases, developers had to learn various techniques for hand-coding server and service connectivity. Connecting to a SOAP web service, for example, used different MXML tags than connecting to a ColdFusion component or PHP class. In addition, you typically needed to code event listeners and fault handlers; concepts that were uncommon and confusing to developers from the traditional web development world.

With Flash Builder 4, Adobe has changed all of that with a brand new approach to building data-centric applications. New Flex developers will be able to quickly connect to data and services and bind the data to rich UI components, and experienced developers will benefit from powerful new ways to build advanced data-oriented applications.

Data-centric development with Flash Builder 4 comprises three main stages:

  • defining a data/service model
  • binding service operations to Flex components
  • implementing advanced data features such as paging and data management

In this article you'll walk through the main steps of building a simple data management application. In this scenario, you have a table in a database and you want to create a Flex application that will allow users to view the data as well as add, update, and delete records.

Step 1: Create a service

Since applications running in Adobe Flash Player cannot interact directly with a database, you need a service that can receive requests from Flex and pass them on to the database; the service will also need to send data from the database back to Flex in a format that it can understand. This remote service can be implemented with any number of technologies, and Flash Builder 4 has built-in support for services created with ColdFusion, PHP, and Java and an extensible framework for supporting other technologies. Other kinds of services can be used as SOAP web services or HTTP services or XML files.

ColdFusion is an ideal choice because it can talk to any back-end database and its easy syntax allows you to create a data access service using just a handful of tags. In addition, ColdFusion already knows how to exchange data with a Flex application using a high performance protocol called AMF. There is AMF support for PHP and Java, too, so feel free to use the server technology with which you're most comfortable and productive.

With ColdFusion, you create a ColdFusion component (CFC) with a function for each data operation that the Flex application will need to perform: get all records from the table, add a new record to the table, delete a record, and so forth. The functions in the CFC can return either weakly or strongly typed data (for example, the getAllRecords function could return a ColdFusion query object or an array of objects if you are developing with a more object-oriented approach); Flex can handle either. The component can also be generated using ColdFusion Builder or by using the generate sample option available in Flash Builder 4 (see Figure 1). Be sure that the access property of the cffunction tags is set to remote and test the component. Now you're ready to set up the Flex application to use the service.

Generate sample component
Figure 1. Generate sample component

Step 2: Build the model in Flash Builder

In Flash Builder 4, the new Data/Services panel is the central location for managing and interacting with all of the servers and services used in your application. The panel displays a tree view to represent all of the types of data and operations available in all of the services. The data and services displayed can come from different sources. For example, one can be a ColdFusion component or PHP class and another can be a third-party RESTful service hosted in the cloud. You, however, don't need to worry about how they're each implemented on the server side. There's now a common way to bind their results to UI components and to write code to invoke operations.

To set up the service for use, Flash Builder 4 will introspect the service and create the tree view automatically. Choose Data > Connect to ColdFusion (or the technology that you used for your service) in Flash Builder 4. For ColdFusion, you simply provide a name that you'd like to use for the service (for example, EmployeeSvc) and point to the CFC on the file system. This step will vary slightly depending on the technology used for the service (you might specify a WSDL for a web service, for example) but the result is always the same: Flash Builder 4 introspects the service to discover what operations and data types it returns, and then builds the tree view of the service in the Data/Services panel.

You can continue to build up the services tree view by adding other services if necessary, or you can begin using that service in the application right away. If the service’s operations are weakly typed, though, one more step is required. A weakly typed operation returns data, but not information about what that data represents.

For example, if your CFC function returns a ColdFusion query object, Flash Builder 4 sees a set of records, but it doesn't know if those records represent a collection of products or employees or sales orders; it's just a collection of data. In order to refer to the results of that operation as a data type, Flash Builder 4 lets you manually configure the type of data that the operation returns. Of course, if you use strong typing on the server side or have used the generate sample option in Flash Builder 4, this step is not required.

To set a return type for a weakly typed service operation, right-click the operation in the Data/Services panel (for example, the getAllItems operation) and select Configure Return Type. This launches a wizard which will help you map the weakly typed data from the server to a strong type in the Flex application. It takes a sample of the operation's actual data and lets you indicate how it should be typed. You specify a name for the custom data type that the operation returns—for example, each record returned could be called an Employee or SalesOrder—and you specify the fields in the data type as well as their format—for example, a string for the first name and a number for the employee id (see Figure 2).

Configure operation return type
Figure 2. Configure operation return type

Step 3: Connect services to UI controls

Now that you've defined all of the operations that your service contains and defined the type of data that they return, you need to show the results of those operations in the application somewhere. The Flex framework contains a number of components that can be bound to data, including data grids, list boxes, form fields, and so on. These components can display data and allow users to interact with your services.

An easy way to get started laying out the UI and binding the components to operations is in Design View. Switch the editor from Source View to Design View. Design View allows you to drag and drop components from the Components panel onto the application's canvas and position them precisely.

Select a DataGrid (grouped under Data Controls in the Components panel) and drag it out onto the page. You'll notice that the grid isn't bound to any data; if you run the application now it will just be an empty grid with three columns. To have the grid display data that comes back from one of your service operations, simply drag the operation from the Data/Services panel and drop it on the grid. When you do, you can choose the data provider (see Figure 3), having done that, the grid will change to display the columns returned by the operation. At this point, you can save the project and run it. You will have a working application with a DataGrid populated by your ColdFusion service and if you want to modify the columns displayed you can do it using the configure columns option. There was no code to write, no event listeners to implement, and no need to know if the service was ColdFusion or Java or SOAP.

There are many other ways that you can use the data types and services to quickly build your application UI. You can generate forms from a data type and create master-detail forms, you can drag and drop a service operation onto a button component to automatically have that operation invoked when the user clicks the button (to invoke a save operation, for example), you can drag and drop operations onto chart components, generate code to just invoke a service operation without binding it to a component and so on.

If you are modifying your server side code often and want to just test your operations, the Test Operation option will be handy, and if you modify or add operations to your service file, Flash Builder 4 automatically refreshes your service to reflect the changes and merge any modifications to your data types that has taken place.

The data and services features are not only useful for getting started in design view. By using the service model, you can get code hinting on all of the operations and data types and you can even customize the generated code for invoking service operations and the behavior of the value objects by extending the generated classes.

Bind To Data
Figure 3. Bind To Data

Advanced data features

The capabilities exposed through new data-centric features of Flash Builder 4 can significantly increase your productivity when creating applications that use data. While it was possible to create the same applications in Flex Builder 3, it required more effort. The new advanced data features, though, go beyond productivity; they enable you to implement functionality that would have been extremely difficult or impossible to do previously.

Client-side data management, for example, is a feature that allows you to map the common data service operations (selecting, creating, updating, and deleting records) on the client to the corresponding data operations on your server. This enables you to perform a number of operations in a batch, enables undo functionality to let your users revert changes, and more.

Another great feature is automatic paging support. If you have a large number of records to display, performance can be a problem if the application needs to fetch and load them all at once. Paging automates the process of fetching a small group of records at a time as needed; all you need is a service that can take arguments specifying a starting row and number of records to fetch in each batch and Flash Builder 4 takes care of implementing all of the client-side logic.

Watch for future articles that will go into these and other data features in more detail.

Where to go from here

Whether you're an experienced Flex developer or you're new to the technology, Flash Builder 4 allows you to easily create rich application experiences that take full advantage of your existing server-side data and service logic. Download the software and start giving your users a new view on data today.


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

More Like This

  • Using Flash Builder 4 to build a Flex application that consumes a .NET-based web service written in C#
  • Flash Builder 4 and PHP – Part 2: Zend AMF and Flash Remoting
  • Flash Builder 4 and PHP – Part 3: Implicit paging and data management
  • Using the Flash Builder 4 data-centric features with Parsley (and other frameworks)
  • Data paging with Flex and PHP using Flash Builder 4
  • Tool-based approaches for data-centric RIA development
  • Set up and build your first Flex and ColdFusion application – Part 3: Use ColdFusion and Flash Builder 4 to create an application
  • Generating ColdFusion forms with Adobe Flash Builder 4
  • Understanding the role of CFCs in Flex application development
  • Deploying a Flex application with ColdFusion URL variables

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

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 © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement