YOUR FEEDBACK
SOA Feature Story: Real-Time SOA Starts with the Messaging Bus!
Gerardo Pardo-Castellote wrote: Regarding the previous comment about "TCP ...


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
MXDJ TOP LINKS YOU MUST CLICK ON !


The Real Estate Sample Application Using ColdFusion and Flash Forms
Create an application that allows users to retrieve records from a database

Digg This!

Page 2 of 3   « previous page   next page »

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 a of 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.

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:

<cffunction name="search"
access="remote"
returnType="query"
output="false"
hint="Returns listings matching the search criteria">
<cfargument name="status" type="string" default="" />
    <cfargument name="priceFrom" type="numeric" default="0" />
    <cfargument name="priceTo" type="numeric" default="0" />
    <cfargument name="hasPool" type="boolean" default="false" />
    <!--- additional arguments removed --->

    <!--- you could also use cfinvoke or access a component in memory
--->
    <cfset var listingGateway
=createObject("component","RealEstate.components.ListingGateway")/>

    <cfreturn
listingGateway.search(argumentCollection=arguments) />
</cffunction>
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 = {};

This object must implement the necessary functions that will be automatically called when the server sends a response from a CFC. The default functions called on this object are onResult and onStatus. The server calls onResult when the service sends a successful response and calls onStatus when the service throws an error, when or some other type of error occurs. That means that the responseHandler object must have those two functions if it is expected to act upon service responses:

responseHandler.onResult = ( results: Object ):Void {
    //handle service response
}
responseHandler.onStatus= (status: Object ):Void {
    //handle error
}

Once the responseHandler objects knows how to behave, the actual service can be instantiated and stored in a global variable (RealEstateAdmin.myGlobalObjects), as follows:

RealEstateAdmin.myGlobalObjects.listingService = connection.getService
("RealEstate.services.ListingService", responseHandler );


Page 2 of 3   « 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 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. That alone made Flash Forms appealing - and with the addition of pieces of ActionScript code, developers were able to create truly responsive forms. But because they were meant to be compatible with HTML forms, they still shared the same submit-refresh model. What if you could 'submit' the form and, without a page refresh, get feedback from the server?
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. That alone made Flash Forms appealing - and with the addition of pieces of ActionScript code, developers were able to create truly responsive forms. But because they were meant to be compatible with HTML forms, they still shared the same submit-refresh model. What if you could 'submit' the form and, without a page refresh, get feedback from the server?
read & respond »
LATEST FLEX STORIES & POSTS
Keys to Success When Load Testing Today's Flex Applications
In today's complex web application world, developers need to test applications that go beyond simple HTTP-based pages. They need to test Rich Internet Applications that incorporate complex technologies like Adobe's Flex. Adobe Flex applications may be different from applications you wo
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
Flex 4 SDK News
Yesterday, a new component architecture and feature specifications were provided to the Flex SDK open source developer community. The Flex team targets three primary teams: design in mind, developer productivity, and framework evolution.
Adobe Gives Yahoo & Google Special Flash Treatment
Adobe says it's going to 'dramatically improve' the search results of dynamic web content and rich Internet applications (RIAs) for Google and Yahoo by giving them optimized Flash Player technology. This new widgetry, which will read and index SWF files, is supposed to uncover informat
Food Dial, a Facebook RIA Application Written in Flex
Food Dial is not just a book of recipes. Here's the big idea - you came back home, tired and hungry. Start the Food Dial application and open the fridge. Here's the red pepper. Turn the dial with food categories...
DreamFace Interactive Delivers Mashup Kit: DreamFace-Fx for Adobe Flex
Following the private Beta release last month, DreamFace Interactive announced the general availability of the DreamFace-Fx Mashup Kit for Adobe Flex. As promised, DreamFace-Fx is the first Mashup Kit to reach developers in a comprehensive roadmap which will extend the DreamFace Open S
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