YOUR FEEDBACK
ASP.NET
mark bosley wrote: Good article. Please post the code or send it to me. It ...
AJAXWorld RIA Conference
$300 Savings Expire July 25
Register Today and SAVE!


2007 West
GOLD SPONSORS:
Active Endpoints
Your SOA Needs BPEL for Orchestration
BEA
Virtualized SOA: Adaptive Infrastructure for Demanding Applications
Nexaweb
Overcoming Bandwidth Challenges with Nexaweb
TIBCO
What is Service Virtualization?
SILVER SPONSORS:
WSO2
Using Web Services Technologies and FOSS Solutions
Click For 2007 East
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP COLDFUSION LINKS


ColdFusion "Real Estate Sample Application" (Part I)
Building the search functionality with Flash Forms

Digg This!

Page 2 of 4   « previous page   next page »

Coding the Search Query
As you may expect, you must write ColdFusion code to search the database. The sample files contain a ColdFusion component (CFC), components/ListingGateway.cfc, that queries the database but you could use a custom tag as well.

The search in this component has several arguments that correspond to the different search criteria: status, price, pool and other amenities, and so forth. It contains a simple query using the cfquery tag. All the arguments have a default value and the SQL statements will vary each time a user specifies a different combination of arguments. For instance, if the user doesn't enter a status, the CFC ignores that criteria; therefore, the SQL statement will not contain that column in its WHERE clause. To exclude it, we used a simple cfif tag (see Listing 1).

When the query finishes processing, the CFC returns the results to the caller through the <cfreturn listingQuery /> tag.

So far, you should be familiar with the methods used. You created a form to request data from the user and wrapped a query in a CFC to retrieve data from a database. You may be wondering how to connect the form and the CFC. Read onward.

Creating the Flash Remoting Service
Flash Remoting is a Macromedia technology that lets Flash Player make asynchronous calls to Web services and receive responses back from the call. During these calls, it can send and receive sets of data. It consists of a gateway that sits on the server and some components that are included in the SWF file. Fortunately, ColdFusion 7 already contains the Flash Remoting gateway, so you don't have to install any additional software. The SWF files generated by Flash Forms also contain the Flash Remoting components because they are used internally.

Just as Web services do, you must place Flash Remoting services in a Web-accessible directory. To create such a service, you use a CFC, writing the functions that you want to provide to the service consumers. These functions must have their access attribute set to remote in order to be accessible to Flash consumers.

Here is a simple example of a service:

<cfcomponent>
<cffunction
name="search"
access="remote"
returntype="query"
output="false"
hint="Returns listings matching the search criteria">

    <cfargument name="status" type="string" default=""/>

<!--- code here that generates a query called myQuery --->

<cfreturn myQuery/>
</cffunction>
</cfcomponent>

We could have included the code that queries the database in the service CFC but it is better to separate presentation from data layers and keep well-defined tasks encapsulated in different components. In this way, the core components that access the database can be completely separate from service components that may access them. The service components, knowing that they are services, can offer additional functionality specifically targeted to Flash, such as formatting.

There is another advantage to this approach. It is common practice to keep components instantiated in a scope that spans several requests, such as the application or session scopes. When a Flash Remoting call is made to a component, however, this component is instantiated at that time - and every time a request is made, a new instance of the component is created.

This means that Flash Remoting cannot call an already instantiated component residing in memory in a shared scope. The only way to resolve this issue is to have a service component that differs from the component that does the actual work. When Flash Remoting calls the service component, this can reference the component residing in memory and make the appropriate invocations. For simplicity's sake, this example instantiates ListingGateway.cfc but the source files use the memory-resident CFC approach (see Figure 4).

Because the Search panel sends simple data types that match the types expected by the ListingGateway component, the service can simply pass the same arguments along by using an argumentCollection (see Listing 2).

Name this component ListingService.cfc and save it in the services folders.

Calling the Service
Now that you have created a service, you are ready to call it. Provided that you are running ColdFusion on your local machine, the Flash Remoting gateway is typically located at http://localhost/flashservices/gateway. That is its default address for ColdFusion installations.

Please note that this address might be different if you are using the built-in Web server option (if your Web root is located at http://localhost:8500).

Adding ActionScript to the Flash Form
To call a service from a Flash Form, you must write some ActionScript. You can add any piece of ActionScript code to the form by writing inline statements in the controls' event handlers, such as onClick, or by writing code blocks in functions using the <cfformitem type="script"> tag that has been added in the ColdFusion 7.01 Updater. For readability and easier maintenance, we recommend using functions.

Because you will use this Flash Remoting service several times, we recommend that you store it in a variable that can be used by other functions and controls. Wrap the Flash Remoting setup code that creates the service and stores this variable in a called setUpRemoting():

<cfformitem type="script">
setUpRemoting():Void{

}
</cfformitem>

Inside the cfformitem tag, declare the connection and service proxy as local variables:

//note the gateway address
var connection:mx.remoting.Connection =
mx.remoting.NetServices.createGatewayConnection
("http://localhost/flashservices/gateway/");

var myService:mx.remoting.NetServiceProxy;

Declare an object that handles all the responses:

var responseHandler:Object = {};


Page 2 of 4   « previous page   next page »

About Nahuel Foronda
Nahuel Foronda is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where he has been creating award-winning applications and offering training for the last five years. He also maintains a blog, called AS Fusion (http://www.asfusion.com), where he writes about Flash, ColdFusion and other web technologies.

About Laura Arguello
Laura Arguello is one of the founders of Blue Instant (http://www.blueinstant.com), a web development firm specializing in Rich Internet Applications where she has been creating award-winning applications and offering training for the last five years. She also maintains a blog, called AS Fusion (http://www.asfusion.com), where she writes about Flash, ColdFusion and other web technologies.

SYS-CON Belgium News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation.
read & respond »
SYS-CON Netherlands News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation.
read & respond »
SYS-CON India News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation.
read & respond »
SYS-CON Italy News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation.
read & respond »
SYS-CON India News Desk wrote: With the release of Macromedia ColdFusion 7 and the arrival of Flash Forms, developers were presented with an alternative to HTML forms that offered them additional functionality, such as full-featured controls not available in HTML and built-in validation.
read & respond »
CFDJ LATEST STORIES . . .
Adobe's Kevin Lynch and Microsoft's Scott Guthrie to Keynote AJAX World RIA Conference & Expo
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be
Voyager Offers Android, .NET CF, Java Runtime Support
Recursion Software released a private beta version of their Voyager mobile platform, with powerful interoperability for Android, Microsoft .NET and Compact Framework (CF), all Java editions (JME CDC, JSE and JEE), and more than 15 embedded operating systems. The Voyager platform is a p
AJAX and Enterprise RIA Tools - JSF, Flex, and JavaFX
2008 is going to be an important year for Rich Internet Applications. Most organizations are delivering or planning to deliver Rich Internet Applications; however, at the same time, most IT managers are facing a dilemma: which Rich Internet Application technology and platform to use? T
CFDynamics Announces Renewed Agreement with SmarterTools
CFDynamics, a ColdFusion web host, has renewed an agreement with SmarterTools that will allow them to pass on immediate value to their customers. When a customers signs up for a dedicated hosting account they will now receive $750 worth of features including SmarterMail, SmarterStats a
Microsoft's Virtualization Chief Mike Neil To Keynote SYS-CON's Virtualization Conference & Expo
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
SYS-CON's Virtualization Conference & Expo: Themes & Topics
From Application Virtualization to Xen, a round-up of the virtualization themes & topics being discussed in NYC June 23-24, 2008 by the world-class speaker faculty at the 3rd International Virtualization Conference & Expo being held by SYS-CON Events in The Roosevelt Hotel, in midtown
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE