WebSolutionscr.com Web Design and Web Development Costa Rica

Web Development & Web Design

Supercharge Your Flex App with ColdFusion Power

Mon 8th , June 2009

By: Kai Koenig


There are quite a few tutorials here at SitePoint that can help you grasp some of the key principles of creating Rich Internet Applications (RIAs) using Flex and AIR.

You'll find that most development undertakings in Flex will involve a back-end application to interact with the Flex client.

Lets discuss some of the theories and principles behind what makes up a Flex application, and then put those principles into practice with a ColdFusion app. We'll assume here that you have some experience already with ColdFusion development. Pay attention, because theres a quiz at the end. The first 100 people to complete the quiz will win themselves a copy of Getting Started With Flex 3, thanks to our sponsor, Adobe.

Take the quiz! Understanding a Rich Internet Applications Architecture From a high level point of view, the common systems architecture of a web application usually comprises three layers. The bottom tier consists of a data storage layer, usually a relational database system such as Microsoft's SQL Server, Oracle, or MySQL. Such a layer provides a relational table model that can be used to store and retrieve application data.

The layer above the data storage layer is known as the application server, or middleware. Commonly used technologies in this playground are Adobe's ColdFusion, Java, PHP, Ruby on Rails, or .NET. Those platforms are used to develop business and data access logic. On top of that, or perhaps even embedded in the middleware, we'll find a layer responsible for HTTP delivery that is, web servers like IIS or Apache.

In Rich Internet Applications, architects sometimes have to deal with other protocols besides HTTP: technologies such as Flash Media Server, for example, support the real-time streaming protocol RTMP. In my earlier tutorial, I showed how a Flex application could communicate with other applications and data on the client side. This time, we'll now communicate with our business and data layers on the server side. How Flex Communicates Flex can access remote data mainly by three different approaches: * HTTP calls to flat files, XML files or dynamic URLs that deliver data Flex can work with * SOAP-based web service calls * Action Message Format (AMF) remote object calls. Each of these methods is represented by different ActionScript classes and MXML tags. Its fair to say that the MXML tag syntax is probably easier to use when coming from a ColdFusion background, because youre comfortable being able to use a similar syntax to ColdFusions CFML syntax.

HTTPService: Retrieving Data Over HTTP Lets think about the tag mx:HTTPService. Unsurprisingly, this is an HTTP-based service, which we can use to grab some data from elsewhere at runtime. In MXML, such a service would be declared as below: The id attribute provides a reference to the service object. The url attribute points to a static XML file thats accessible via HTTP, but could also point to a local file, like so: In this case the Flex application would expect to find the xml file in the same path as itself. Naturally, its possible to have ColdFusion generate some XML for us. Heres a very simple way of doing this: Taxes 2000 ... #xmlContent# The tag stores created static or dynamic content in a variable, xmlContent.

We then use a cfcontent tag to reset any output we may have created earlier and specify a text/xml content-type. We then deliver the content of the variable xmlContent using a simple cfoutput tag. Voil, out comes some XML.

Marketing Colum