Capability and Performance with Web Services/Remoting
Each of the previous methods for loading external data involved loading an entire text file of variables at once. With the use of Flash remoting or Web services, you now have the ability to connect to an object on an application server and to exchange discrete pieces of data with that object. This allows for vast performance increases, as well as the ability to create more complex applications.
Figure 2 shows an interface for the song requestor module of Radio Free Astoria (http://radio.tapper.net). This module connects to a ColdFusion Component (CFC) and uses one method to retrieve an array of artists, another to retrieve an array of songs for an artist, and a third method to send an e-mail with the details of the requested song. Listing 1 shows the source code for the ColdFusion Component.
|Figure 2. Song Requestor Interface: This simple interface allows users to browse through the songs available for an artist and to make a request that a particular song be played.|
This ColdFusion Component has four methods (each defined with a <cffunction> tag). The first method queries for all artists, and returns an array of them to Flash. The second takes an artist name as an argument (defined with the <cfargument> tag), and queries for all songs by that artist, returning an array of songs. The third method processes the song request, taking the artist and song name as arguments, and e-mailing the request (using a <cfmail> tag). The final method is used to convert the results of a query (such as those in the first two methods) to an array of objects, easing the use of the data in Flash.
By implementing this functionality in a ColdFusion Component, you have the ability to use the same methods from both traditional ColdFusion/HTML pages, as well as from technologies capable of using Web services or Flash remoting. For simplicity sake, the code shown in Listing 2 makes use of Web services and Flash MX Professional 2004's WebServiceConnector component. A future article may address implementing this same solution using the WebServices classes (without the use of the component) or Flash remoting.
Assuming a simple interface (shown in Figure 2) of two list boxes, a text field, a button, and three WebServiceConnector components drawn on the stage in Flash, the ActionScript below defines the corresponding functionality. The handleEvent method routes all the broadcast events to their appropriate handlers.
The same ActionScript from Listing 2 would work identically regardless of which technology you choose to implement the Web service.
Shedding its Past
Flash has become a very powerful tool for building application interfaces, and its power grows exponentially by connecting it to an application server. What application server you choose is a matter of preference, but if you are comfortable working with HTML, XML, and other tag-based solutions, ColdFusion would be a good fit; it is easy to learn, allows for ultra rapid development, and offers great power for applications. Additionally, ColdFusion's native support for Web services and Flash remoting will make the going extra easy when you're ready to integrate your data into Flash applications
Regardless of which application server you choose, using Flash for the front end will give you all the richness and interactivity of client-server applications but without all the distribution issues. And it's platform and browser independent; all you need is the Flash player. It's taking awhile for Flash to shake its reputation as an 'animation tool,' but more and more frequently, large companies are making the transition to intranet- and extranet-based applicationsand powering them with Flash.