Web Design Resources & Tutorials to help you design the best website!
Understanding the RemoteClass Metadata and its use in Flex and ColdFusion
understanding flex data management by using coldfusion livecycle
Simple Login Form Example using Flex and ColdFusion WebService
Flex and ColdFusion Remoting Simple DataBase Example
Very Simple Instant Message Client using ColdFusion, Flex, and LiveCycleSherifAbdou.com is a web design blog that we created with goal of provoking inspiration to other designers & webmasters all over the internet
Here is an example of how to use the RemoteClass metadata in Flex to map Actionscript objects that map directly onto ColdFusion Component that is found on a remote server. The data then can be converted to an Actionscript class with the appropriate properties and referenced in another actionscript class or MXML. My Workspace is under wwwroot/
; package vo { /** * @private * What we need to do is map on this actionscript file * the coldufusion component, this is done by using the Remote * Class Metadata tag. so [RemoteClass(alias="from(wwwroot Folder).path.to.coldFusionCFC")] * Everything has to match exactly between the variables declared here and the coldFusion arguments * that will be declared in the CFC file otherwise it will not work at all. ALso we want this class to be * Bindable so we can show some information to know that it works */ [RemoteClass(alias="RemoteClassExample.src.cfc.cfcVO")] [Bindable] public class ColdFusionFlexVO { /** * @private * What we will be creating are simple variables to * prove the point, this can be used for a registration form for example. * Make Sure when you write in the Coldfusion component you use the same * exact name, case does matter. * Now Go to the cfcVO.cfc file under cfc */ public var firstName:String; public var lastName:String; public var emailAddress:String; public var password:String; public function ColdFusionFlexVO() { } public function toString():String { var result:String= " "; result += "First Name : "+ firstName +"\n" + "Last Name : " + lastName + "\n" + "Email Address : " + emailAddress +"\n" + "Passwrod : " + password; return result; } } }
<!-- What we need now is to give an alias to the cfcomponent tag which is basically where this file is stored--> <cfcomponent output="false" alias="RemoteClassExample.src.cfc.cfcVO" style="rpc"> <!--Create The Properties that will be used, Match them exactly with these public var firstName:String; public var lastName:String; public var emailAddress:String; public var password:String; Including the type --> <cfproperty name="firstName" type="string"/> <cfproperty name="lastName" type="string"/> <cfproperty name="emailAddress" type="string"/> <cfproperty name="password" type="string"/> <!--Now We place the arguments that we will be using which is what we will passing in when we create a remote object in flex, the return type is the name of the coldfusion cfc file which is cfcVO--> <cffunction name="returnVOClassObject" returntype="cfcVO" access="remote"> <cfargument name="firstName" required="true" type="string"/> <cfargument name="lastName" required="true" type="string"/> <cfargument name="emailAddress" required="true" type="string"/> <cfargument name="password" required="true" type="string"/> <!--Now set the property to the argument and return it--> <cfset this.firstName = arguments.firstName /> <cfset this.lastName = arguments.lastName /> <cfset this.emailAddress = arguments.emailAddress /> <cfset this.password = arguments.password /> <!--Return the entire cfc, which will mean that we are really returning a COldFusionFlexVO--> <cfreturn this> <!--Move on to the MXML File--> </cffunction> </cfcomponent>
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" creationComplete="onCreateComplete()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import vo.ColdFusionFlexVO; /** * @Private * Create the class and pass to it values so we see that it works */ [Bindable] private var remoteVO:ColdFusionFlexVO; private function onCreateComplete():void { remoteSend.returnVOClassObject("Adobe","Flex","Adobe@flex.net","ColdFusion"); } private function onResultEvent(event:ResultEvent):void { remoteVO = event.result as ColdFusionFlexVO; //where our ColdFusionFlexVO class will be populated myText.text = remoteVO.toString(); } private function onFaultEvent(event:FaultEvent):void { mx.controls.Alert.show(event.fault.toString(),"Fault"); } ]]> </mx:Script> <!--The Remote Object--> <mx:RemoteObject id="remoteSend" destination="ColdFusion" source="RemoteClassExample.src.cfc.cfcVO"> <mx:method name="returnVOClassObject" result="onResultEvent(event)" fault="onFaultEvent(event)"> </mx:method> </mx:RemoteObject> <mx:TextArea id="myText" width="200" height="200"/> </mx:Application>

Copyright ®2008 - SherifAbdou – The Design Blog
1 Response to Understanding the RemoteClass Metadata and its use in Flex and ColdFusion
Kevin Penny
May 29th, 2009 at 5:48 am
Excellent – My question is, what if your 'returnVOClassObject' component returned 'void' and merely populated itself – and cfreturn'd nothing? Is there a way in flex to be able to declare your object (which exists mapping to a cfc like you have) but merely call a 'read(obj)' on the obj (object) through the remoteObject call – and have that object be fully populated?? I'm getting 'null' in the event.result value – and the object I passed into it is not getting populated.
Thanks