Sunday 01 Aug 2010   
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

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 

Rosetta Stone