Sunday 29 Jan 2012   
Add Comment

Simple RemoteObject Tutorial

Flex / ColdFusion Tutorial #1

This is a simple tutorial showing how to communicate between Flex & ColdFusion. The tutorial makes a simple call to a CFC and returns the current time.

Demo.mxml

Lines 6 - 10 simply import the ResultEvent and define an event handler for our remote connection. Line 9 does the work, setting the label text to the remote object result.

Lines 14-16 setup the remote object. This tutorials like all tutorials on this site, use a ColdFusion mapping called flexcf to get access to the ColdFusion CFC's. So flexcf.1.DemoCFC is a pointer to the Demo.CFC in a directory called 1. The flexcf mapping points the the tutorial base directory D:\FlexCF\tutorials\ for example. We define the function for handling a successful call on line 15.

Line 18 just sets up an empty label field to display the result in
Line 19 creates a button that calls the remote object method getServerTime(). getServerTime is a method in the CFC.



DemoCFC.cfc

This is very simple. It is important to remember that the CFC methods need to have access set to "remote".

This just returns a string, which is the result of now(). The current server time.



Demo

See this code running!


Download

Download this code as a zip!


Comments

This example is great, but how do I connect to remote CF server on another machine with the component files residing in that machine? I specify the path to the other machine in the endpoint property of remoteobject but it gives error "Send Failed". An example would be appreciated.
Ambika Dayal @ Thursday 19 Feb 2009 - 01:45:24 AM

You can specify the endpoint on the remoteObject ie: endPoint="http://mysecondserver.com/flex2gateway"
http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/mxml/RemoteObject.html
If you do this you will need to setup a crossdomain.xml files to allow access from the remote server.
Paul Kukiel @ Thursday 19 Feb 2009 - 02:31:10 AM

Hi All,

I am trying to run simple project on CF9 (with JRun)-Flex integrated project. But when I try to run the application I encountered below error –

[RPC Fault faultString="Send failed" faultCode="Client.Error.MessageSend" faultDetail="Channel.Ping.Failed error null url: 'http://stplt542:80/flex2gateway/'"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvok er.as:220]
at mx.rpc::Responder/fault()[C:\autobuild\3.2.0\frameworks\projects\rpc\ src\mx\rpc\Responder.as:53]
at mx.rpc::AsyncRequest/fault()[C:\autobuild\3.2.0\frameworks\projects\r pc\src\mx\rpc\AsyncRequest.as:103]
at mx.messaging::ChannelSet/faultPendingSends()[C:\autobuild\3.2.0\frame works\projects\rpc\src\mx\messaging\ChannelSet.as:1482]
at mx.messaging::ChannelSet/channelFaultHandler()[C:\autobuild\3.2.0\fra meworks\projects\rpc\src\mx\messaging\ChannelSet.as:975]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/connectFailed()[C:\autobuild\3.2.0\frameworks\p rojects\rpc\src\mx\messaging\Channel.as:997]
at mx.messaging.channels::PollingChannel/connectFailed()[C:\autobuild\3. 2.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.a s:354]
at mx.messaging.channels::AMFChannel/faultHandler()[C:\autobuild\3.2.0\f rameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:477]
====
Here is the service-config.xml file –
<channel-definition id="my-cfamf" class="mx.messaging.channels.AMFChannel">
<endpoint uri="http://stplt542:80/flex2gateway/" class="coldfusion.flash.messaging.CFAMFEndPoint"/>

Nothing else was changed in service-config.xml file.

I have not changed anything in CF Admin apart from enabling the Flash Remoting Support.

Do I need to do some more configuration changes on Admin Side or in config xml files?

Please help me on that.
Sanoop @ Wednesday 16 Feb 2011 - 04:54:27 AM

Does http://stplt542:80/flex2gateway return a white screen?
Paul @ Wednesday 16 Feb 2011 - 04:08:41 PM

I ran this code and once I pressed the button it clocked indefinitely. I may have the files in the wrong place. My Demo.xmxl file is in c:/Will/My Documents/Flex builder 3/test2/src. Where should file DemoCFC.cfc reside?
Thanks
Will Maynard @ Tuesday 22 Mar 2011 - 04:39:44 AM

The cfc needs to be in the webroot.
Paul @ Tuesday 22 Mar 2011 - 08:59:36 AM

@Paul,
Thank for replying Paul. and sorry for replying late I was running out of station.
Yes Paul http://stplt542:80/flex2gateway returns a white(blank) screen.
Sanoop @ Tuesday 22 Mar 2011 - 06:53:40 PM

@Sanoop I'm not sure what's going on there. You should be able to leave the xlf config files alone. If you want me to take a closer look feel free to contact me via my blog.
Paul @ Wednesday 23 Mar 2011 - 09:59:24 AM

Click button to add a comment


Author

Dale Fraser


Published

Thursday 17 Apr 2008

Tags

cfcomponent  cffunction  cfreturn  mx:Application  mx:Button  mx:Label  mx:RemoteObject  mx:Script