Home > Adobe Flash, Adobe Flex, ColdFusion, Events > Flex 4 & ColdFusion 9 Remoting Recap

Flex 4 & ColdFusion 9 Remoting Recap

It’s been a couple of years since I worked with ColdFusion and Flex together, but I remember I always like the combination and chose it for my new little Xuland social networking project I’ve been working on (see previous posts).

I had to remember how the whole Flex-ColdFusion remoting setup would work again and I had to overcome a couple of hurdles. I thought I’d share the experience as it would have helped me get up to speed quickly.

Here’s a quick recap of setting up your Flex application to remote to ColdFusion:

  1. Install ColdFusion (I installed mine to the default C:\ColdFusion9 directory)
  2. In FlexBuilder, create a new Flex project
  3. While creating the project, select an Application server type of “ColdFusion” and check the “Use remote object access service” with the “ColdFusion Flash Remoting” option selected.
    .
    servertechnology
  4. On the next screen, in my case I’m using a Standalone installation and had to uncheck the “Use default location for local ColdFusion server”. Of course, the root folder was C:\ColdFusion9. I clicked Validate Configuration which validated that the root folder existed.
    .
    serverlocation
  5. I happen to use ColdFusion primarily for access to a MySQL datasource, so I had to setup the datasource in the ColdFusion admin first (this information should be readily available anywhere)
  6. Once the datasource was setup, I first created a value-object (VO) in ColdFusion to represent the object (in this case, a User) I wanted to pass back to the Flex application
    .
    UserVO.cfc:

    1
    2
    3
    4
    5
    
    <cfcomponent output="false" alias="com.xyz.coldfusion.vo.UserVO">
    	<cfproperty name="userID" type="numeric"/>
    	<cfproperty name="username" type="string"/>
    	<cfproperty name="password" type="string"/>
    </cfcomponent>
  7. After the VO, I created a data-access object (DAO) to query the datasource for a user and return a UserVO to the calling Flex application
    .

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    <cfcomponent output="yes">
    	<cffunction name="getUserByID" 
    		access="remote" 
    		returntype="com.xyz.coldfusion.vo.UserVO">
     
    		<cfargument name="userID" type="numeric" required="yes"> 
     
    		<cfquery name="getUser" datasource="xuland">
            	SELECT * 
    		FROM tblUsers
    		WHERE userID = '#userID#'
    		</cfquery>
     
    		<cfreturn getUser>
     
    	</cffunction>
    </cfcomponent>
  8. Back in the Flex project, I setup my RemoteObject tag to point towards the ColdFusion DAO component I created in the last step:
    .

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    <!-- Remote Services -->
    <mx:RemoteObject id="userService"
    	 destination="ColdFusion"
    	 source="com.xyz.coldfusion.dao.UserDAO"
    	 showBusyCursor="true">
     
    	<mx:method name="getUserByID" 
    		   result="resultHandler(event)" 
    		   fault="faultHandler(event)"/>
     
    </mx:RemoteObject>
  9. Create your result and fault handlers (here we just display an Alert)
    .

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    <fx:Script>
    	<![CDATA[
    		import mx.controls.Alert;
    		import mx.rpc.events.FaultEvent;
    		import mx.rpc.events.ResultEvent;
     
    		private function resultHandler( event : ResultEvent ) : void
    		{
    			Alert.show( event.result.toString() );
    		}
     
    		private function faultHandler( event : FaultEvent ) : void 
    		{
    			Alert.show( event.fault.faultString );
    		}
    	]]>
    </fx:Script>
  10. Finally create a button or method to call the service:
    .

    1
    
    <mx:Button click="userService.getUserByID( 1 )"/>
  11. Much of this logic may be abstracted off into controllers, delegates, commands or other framework-specific components but this is a fairly simple example of installing, configuring and executing a remote object service call from Flex to ColdFusion.

Categories: Adobe Flash, Adobe Flex, ColdFusion, Events Tags:
  1. February 5th, 2012 at 03:52 | #1

    Really appreciate you sharing this blog article. Keep writing.

  2. June 27th, 2013 at 12:56 | #2

    Hi, I desire to subscribe for this blog to obtain hottest updates, therefore where can i do it please help out.

  3. April 10th, 2014 at 02:35 | #3

    DASHCOM websites are springing up all over the world.

    Just just because a link is on Piratebay does not mean that the users
    are getting, and hence, the flawed data. The vulnerability has apparently been fixed
    since interview with Russo occurred, and usernames are again safe and
    secure.

  4. April 11th, 2014 at 00:03 | #4

    One of the very most lucrative businesses women will go into is the creation of
    accessories. s no secret that illegal file sharing continues to be rampant in several countries, like
    the US, however, it will not be government interference that eventually leads on the
    end with the age of illegal downloads. The free Lyrics Search
    app can be obtained at the Android Market.

  5. May 19th, 2014 at 06:23 | #5

    I’ve been surfing on-line more than 3 hours
    these days, but I never discovered any attention-grabbing article
    like yours. It is pretty value sufficient for me.
    In my view, if all web owners and bloggers made just right content material
    as you did, the internet will be a lot more helpful than ever before.

  6. May 21st, 2014 at 05:44 | #6

    It’s amazing to pay a visit this site and reading the views of all friends regarding this article, while I am also eager of getting familiarity.

  7. July 24th, 2014 at 22:39 | #7

    In the restaurant, we can create a little more,
    and we do serve more people,” he said. They seemed desparate, and though I didn’t like boarding I said Ok. These types of books also provide accounts of the author’s achievement and also flaws that you can avoid and use to your advantage. The profitability of wind farms will therefore be higher if their production schedule coincides with these periods. Careful on-line research will turn up a multitude of opportunities for the ambitious virtual real estate wholesaler. Due to its compact size, contractors use it in close working conditions. If you want to invest in a piece of commercial real estate, think about the kind of tax breaks and benefits you might receive. The scope of these inspections is to document the condition of the property in both a written and photographic format before and after the tenant has occupied the premises. The intention is that your home will gain in value over time and that equity in your home will build as you age. They had called him, and I don’t know what they said, but somehow they had convinced him, not that I was dangerous along with my dogs, but that they were the culprits.

  8. August 22nd, 2014 at 20:02 | #8

    Of course, they can spider their own Google+ site, but
    it has yet to reach universal adoption. Times have
    definitely changed from when we used to peruse through
    a newspaper to find an apartment. It is better not to ignore Word – Press
    SEO training as it is very much necessary to be successful online.

  9. August 24th, 2014 at 02:51 | #9

    With that said, there is still a good chance that an offer will be accepted
    if you truly cannot afford to pay your back taxes. Accounting software will automate your
    transactions, which helps eliminate a chance for error caused
    due to manual data-entry mistakes. Many taxpayers choose to contact TAS because they
    are dealing with a tax debt.

  10. November 15th, 2014 at 14:06 | #10

    For latest news you have to pay a quick visit the web and on the web
    I found this web site as a best website for most up-to-date updates.

  11. February 19th, 2015 at 00:26 | #11

    Quality articles or reviews is the secret to attract the viewers to visit the web page, that’s what this website is providing.

  12. April 14th, 2015 at 21:55 | #12

    They want to know about the sites you want to visit, your emails, your
    interests, your location and so on. Same method as above only you post
    music, download software called “supermp3download” (find it on torrent sites) and download music that other medication is searching for, should you
    be familiar with google alert you might set up an email alert when someone searches for music.
    However, the new measures won’t terminate internet use following
    your ‘three strike’ deal other countries have.

  1. No trackbacks yet.