|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV SYS-CON.TV WEBCASTS |
MXDJ TOP LINKS YOU MUST CLICK ON ! ColdFusion
The Real Estate Sample Application Using ColdFusion and Flash Forms
Create an application that allows users to retrieve records from a database
Feb. 12, 2006 05:00 PM
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 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> 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"
Calling the Service 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 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"> Inside the cfformitem tag, declare the connection and service proxy as local variables:
//note the gateway address 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 { 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 Page 2 of 3 « previous page next page »
LATEST FLEX STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||