Flex Remote Object examples

  • I’m going to put my notes on how to have RemoteObject work for Adobe Flex Builder 3 for the desktop and server.  I personally like the idea of coding on the server since there are less surprises.
  • 1.) Creating an Application from your desktop 

  • Following these steps when creating your flex project. project name : test_rs1 project location : d:\\cf9\wwwroot\apps\flex\test_rs1 

    Application Type : Web Application 

    Application server type: ColdFusion 

    Use remote object access service [ checked ] 

    ColdFusion Flash Remoting [ checked ] 

    ColdFusion Installation type: standalone 

    Web Root: d://cf9/wwwroot 

    Root URL: http://localhost:8500/ 

    ColdFusion WAR: d:/cf9/wwwroot/cfusion-ear/cfusion-war/ 

    Main source folder: src 

    Output folder URL: bin-debug 

    * Flex App: I copied this code and compiled the code via the ‘run’ button. 

    <?xml version=”1.0″ encoding=”utf-8″?> 

    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” 

    layout=”absolute” viewSourceURL=”srcview/index.html”> 

    <mx:Script> 

    <![CDATA[ 

    import mx.controls.Alert; 

    import mx.rpc.events.FaultEvent; 

    import mx.rpc.Fault; 

    import mx.rpc.events.ResultEvent; 

    // send 

    public function WelcomeMsg():void { 

    Alert.show(test_name.text); 

    ws.WelcomeMsg(test_name.text ); 

    // result 

    private function onResult( e : ResultEvent ) :void { 

    msg.text = e.result.toString(); 

    // error msg 

    private function onFault( e : FaultEvent ) :void { 

    msg.text = e.fault.faultString; 

    ]]> 

    </mx:Script> 

    <mx:RemoteObject id=”ws” 

    destination=”ColdFusion” 

    source=”apps.flex.test_rs1.src.NEWCFComponent” > 

    <mx:method name=”WelcomeMsg” 

    result=”onResult(event)” 

    fault=”Alert.show(event.fault.message, ‘Erro’)” /> 

    </mx:RemoteObject> 

    <!– 

    <mx:method name=”WelcomeMsg” 

    result=”onResult(event)” 

    fault=”Alert.show(event.fault.message, ‘Erro’)” /> 

    –> 

    <mx:Button x=”284″ y=”10″ label=”Get Welcome Message.” 

    click=”WelcomeMsg()” /> 

    <mx:TextInput id=”msg” x=”481″ y=”10″ width=”300″ /> 

    <mx:TextInput id=”test_name” x=”116″ y=”10″ width=”150″ /> 

    <mx:Label x=”10″ y=”12″ text=”Enter your name:” /> 

    </mx:Application>

    * ColdFusion CFC: Save this cfc as [NEWCFComponent.cfc] in the same folder as src. You will notice that I append to a log file so I can verify that the cfc is being executed.

    <cfcomponent displayname=”CF_Service” output=”false”> 

    <cffunction access=”remote” returntype=”string”>
    <cfargument required=”yes” default=”default message… “> 

    <cfset v_now = Now() & ” <br />” >
    <cffile action=”append” addnewline=”yes”
    file=”#GetDirectoryFromPath(GetBaseTemplatePath())#cfc_log_file.html”
    output=”#v_now# date=YO, #test_name#!” fixnewline=”no” > 

    <cfreturn “YO, #test_name#!”>
    </cffunction> 

    </cfcomponent> 

    * Test CFC: One should make sure one doesn’t get an error from this specific method in the CFC. One should use default values for all of the CFC arguments. 

    http://localhost:8500/apps/flex/test_rs1/src/NEWCFComponent.cfc?method=WelcomeMsg 

    * Run a Flex Application via the ‘RUN’ button. After you compile the application, it will launch a browser of the flex page. One will put your ‘name’ in the first box and click on the button. You will notice the ‘YO’ and your name in the second box coming from the cfc.

    https://localhost:8500/flex/test_rs2/bin-debug/test_rs2.html

  •  

    2.) Create a Flex Application on your web server 

  • * Following these steps when creating your flex project.project name : test_rs1 project location : \\[server-name]\reg\apps\flex\test_rs1 

    Application Type : Web Application 

    Application server type: ColdFusion 

    Use remote object access service [ checked ] 

    ColdFusion Flash Remoting [ checked ] 

    ColdFusion Installation type: J2EE

    Web Root: \\[server_name]\regroot\

    Root URL: https://domain_name.com/

    ColdFusion WAR: \\[server_name]\regroot\cfusion-ear\cfusion-war\

    Main source folder: src 

    Output folder URL: bin-debug 

    * Flex App: I copied this code and compiled the code via the ‘run’ button.

    <?xml version=”1.0″ encoding=”utf-8″?>

    <mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221;

    layout=”absolute” viewSourceURL=”srcview/index.html”>

    <mx:Script>

    <![CDATA[

    import mx.controls.Alert;

    import mx.rpc.events.FaultEvent;

    import mx.rpc.Fault;

    import mx.rpc.events.ResultEvent;

    // send

    public function WelcomeMsg():void {

    Alert.show(test_name.text);

    ws.WelcomeMsg(test_name.text );

    }

    // result

    private function onResult( e : ResultEvent ) :void {

    msg.text = e.result.toString();

    }

    // error msg

    private function onFault( e : FaultEvent ) :void {

    msg.text = e.fault.faultString;

    }

    ]]>

    </mx:Script>

    <mx:RemoteObject id=”ws”

    destination=”ColdFusion”

    source=”flex.test_rs2.src.NEWCFComponent” >

    <mx:method name=”WelcomeMsg”

    result=”onResult(event)”

    fault=”Alert.show(event.fault.message, ‘Erro’)” />

    </mx:RemoteObject>

    <mx:Button x=”284″ y=”10″ label=”Get Welcome Message.”

    click=”WelcomeMsg()” />

    <mx:TextInput id=”msg” x=”481″ y=”10″ width=”300″ />

    <mx:TextInput id=”test_name” x=”116″ y=”10″ width=”150″ />

    <mx:Label x=”10″ y=”12″ text=”Enter your name:” />

    </mx:Application>

    ColdFusion CFC: Save this cfc as [NEWCFComponent.cfc] in the same folder as src. You will notice that I append to a log file so I can verify that the cfc is being executed.

    <cfcomponent displayname=”CF_Service” output=”false”>

    <cffunction name=”WelcomeMsg” access=”remote” returntype=”string”>

    <cfargument name=”test_name” type=”string” required=”yes” default=”default message… “>

    <cfset v_now = Now() & ” <br />” >

    <cffile action=”append” addnewline=”yes”

    file=”#GetDirectoryFromPath(GetBaseTemplatePath())#cfc_log_file.html”

    output=”#v_now# date=YO, #test_name#!” fixnewline=”no” >

    <cfreturn “YO, #test_name#!”>

    </cffunction>

    </cfcomponent>

    * Test CFC: One should make sure one doesn’t get an error from this specific method in the CFC. One should use default values for all of the CFC arguments. 

    http://[domain-name.com]/flex/test_rs1/src/NEWCFComponent.cfc?method=WelcomeMsg 

    * Run a Flex Application via the ‘RUN’ button. After you compile the application, it will launch a browser of the flex page. One put you ‘name’ in the first box and click on the button. You will notice the ‘YO’ and your name in the second box.

    https://[domain-name.com]/flex/test_rs2/bin-debug/test_rs2.html

  • Advertisements

    Site of the Day 6/15/2010

    Here is a good site using ColdFusion and Flex.

    http://flexcf.com/home

    Site of the Day 6/14/2010

    Here is funny article from Mozilla about Apple Safari’s HTML 5 demo and how intellectually dishonest it is coming from Apple’ marketing department. Good figure…I’m so surprised 🙂

    http://www.0xdeadbeef.com/weblog/2010/06/intellectual-honesty-and-html5/

    Site of the Day 6/13/2010

    Here is the fourth part of an article to increase performance of Flex applications.

    http://www.insideria.com/2008/07/flex-ria-performance-considera-3.html

    Site of the Day 6/12/2010

    Here is the third part of an article to increase performance of Flex applications.

    http://www.insideria.com/2008/06/flex-ria-performance-considera-2.html

    Site of the Day 6/11/2010

    Here is the second part of an article to increase performance of Flex applications.

    http://www.insideria.com/2008/04/flex-ria-performance-considera.html

    Site of the Day 6/10/2010

    Here is the first part of an article to increase performance of Flex applications.

    http://www.insideria.com/2008/03/flex-ria-performance-considera-1.html