Publishers of technology books, eBooks, and videos for creative people

Home > Blogs > Data/Services in Flash Builder

Data/Services in Flash Builder

If, like me, you believe that data is the key to a great Rich Internet Application, then the Data/Services tools built into Flash Builder are for you! Check out this post to learn how the new Data/Services panel will help you develop a bug-free client-server application in no time.

The first thing you'll need to make use of in a data service is the service, which is to say a server. Flash Builder naturally supports Adobe's server technologies—BlazeDS, ColdFusion, and LCDS—but also has increased support for PHP, an open-source scripting language (and my personal favorite server technology). Flash Builder also has the more generic HTTP, Web Service, and XML connectors, which don't care what the underlying server technology is. In any case, the first step is identifying the URL for the service, whether it's something you create yourself (e.g., your own PHP script on your server) or it comes from a third-party such as Yahoo! or Amazon.

Once you've established or identified the data service, select Data > Connect to X to start the service wizard, where X is a specific type (Figure 1).


If you just choose Connect to Data/Service, you'll then be able to choose from the others on the next screen. If you're connecting to a PHP script, you might be surprised to know that you don't necessarily select Connect to PHP. That option is specific for using AMF (Action Message Format) with a PHP script. The PHP script itself would actually use a third-party library such as AMFPHP or Zend AMF to handle the AMF format. If the PHP script returns just plain text, JSON, or XML, you can most likely use the Connect to HTTP option. My focus in this post isn't really on the individual Connect to X wizards, but rather what you have once you've used them, so just as a frame of reference, I'll proceed with an HTTP example.

When you select the Connect to HTTP option, you'll be prompted to (Figure 2):

  • Name the operation (something meaningful)
  • Indicate the method (normally GET or POST)
  • Indicate the URL
  • Name the service (again, something meaningful)



If the service takes any parameters, you can indicate those as well. For example, a service that returns a list of products might take a category name or ID to restrict the list. Or a service for adding new products would likely take several parameters corresponding to the atomic bits of information for each product.

After completing the Connect to HTTP wizard, Flash Builder will create a representation of the service as an ActionScript file, although it won't create a call to that service. And now, the Data/Services panel comes into play. If it's not already visible at the bottom of the workbench, select Window > Data/Services.

The Data/Services panel is a one-stop resource for all of the services registered with an application. But registering a service and using this panel, you will absolutely save yourself lots of time and create a more reliable application. I'll explain...

If you just run a Connect to X wizard, the Data/Services panel will only reflect the service name and its operations. You can, at this point, right+click (Windows) or Control+click (Mac OS X) on an operation to bring up a contextual menu. From the options, the Test Operation item gets you to an interface where you can test the operation to confirm that it's working. Moreover, testing the operation validates what information must be sent to the service and what will be returned. This is great, but there's more...

The Data/Services panel can reflect not just the registered services but also the data types involved. For example, say that the service returns meteorological information as a custom object. You can use the Data/Services panel to create a representation of that custom object as a value object: a new, custom ActionScript data type. To do that, bring up the contextual menu on an operation and select Configure Return Type.

In the first window, you'll want to select Auto-detect... (the default) and then click Next. You can enter authentication credentials, too, if those are required. The next window will give you the option of entering sample parameters, such as a product category. In the final window, you'll be presented with information about the returned data (Figure 3). You can use this to create a new name for this data type, as well as customize the type to some degree. For the example in Figure 3—an RSS feed, there's a ton of information returned.


Once you've configured the return type, new ActionScript classes will be created to represent the data type (or types). This brings a whole slew of benefits, not the least of which is code hinting, code completion, and compiler checks when using that data type. You'll also see that the Data/Services panel will now list the data types involved with the service.

By bringing up the contextual menu on the data types and the operations, you'll be presented with quick ways to generate forms based upon the operation or type, generate service calls, enable data management and paging, and so forth. Returning to the products example, if one operation returned a list of products, you could just drag that operation from the Data/Services panel onto a DataGrid or List component to use the operation as the data provider for that display control. Or, if an operation was for creating new products, you could have Flash Builder generate an "Add Product" form based upon what's known about the product data type. These are just two practical examples of how you would use the registered services and data types.

By utilizing the Data/Services panel, not only will you develop your client-server applications faster (because you'll be hand coding so much less), you'll also be less likely to make mistakes (because you'll be hand coding so much less!). Try it and see for yourself!