Uncategorized
How I create a Flex Project with ColdFusion
I have seen a lot of emails and blog posts with folks wanting to know how to connect their flex application to a remote ColdFusion server. At first I thought this was a really silly question, because its not much different than connecting to a local one. But then I realized that this was clear for me because I was not setting up my projects using the ColdFusion option in the Flex Builder new project wizard.
Because I started my flex 2 adventures on my mac, using only the Flex 2 SDK and the command line compiler, I look at creating my projects a little differently. But also when i begin a project I dont feel its a good idea to commit my self to any one of the RPC services.
So when I create a new flex project I always choose the “Basic” project type. I specify the name of my project and where I want my files to live. I then begin working on my application, building the layout and controls that make up the GUI. WHEN I am ready to look at connecting to a remote service for data processing, I walk through these steps.
- Create a “libs” directory at the root of my project. (name and location is really arbitrary)
- Copy the services config file from my ColdFusion instance (or another project) to this directory
- Add a new option to the compiler settings for the project which specifies the location of the config file. (ie. –compiler.services=libs/services-config.xml)
- In my services-config.xml I specify the exact path to the cf server I wish to access in my cf-amf channel definition
< endpoint uri="http://simb.net/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/ >
I feel this method has several benefits. The first being that my project is now independent of any other projects using the ColdFusion destination on this server. Which means if I change the config file in cf (or in another project) my project will continue to function as I expect. The second benefit is that my application doesn’t have to take into account how this information is set. For instance Mike Nimer posted an excellent way to get rid of the services-config.xml file all together in your application. But I feel his method is quite a bit of work for something a few lines of xml take care of very nicely. And the third point is that I can actually use ANT to change the value of the server path as part of a deployment script, so I can have my application compile for local or remote server usage very easily.
I hope if you were confused about a solution for doing remote cf development in flex this might help you simplify your process. I know for me it did because I didnt realize there was such a problem ![]()
02 Feb 2007 Simeon

Great tip, cheers
Thank you so much. After hours of trying to work on a shared hosting environment this example solved all my problems simply and quickly. Thank you again.
hi,
Thanks for this post!
I have been trying, but have not been able to connect to the flex2 gateway on my localhost. Have you been able to use it, as I know you use the Mac as well? I get a 500 error when I try to view http://localhost/flex2gateway/
Maybe now I can try my remote host
Thanks again!
Hey John,
When you go to that url you should not see anything at all. Just a blank screen. So if you are getting a 500 error that leads me to believe there is something else wrong. Have you configured your mac to use apache with ColdFusion? If not then you will want to use the port your CF server is running on in addition to that url. So something like http://localhost:8500/flex2gateway/
You might try just browsing to that path in a browser with the correct port and seeing what you get. Because it should just be a blank screen. Let me know how it goes.
sim
HI Simeon,
Thanks so much for your help:)
I have the multi-version with JRun 4, I installed it with the defaults, and yes I have it configured with apache. When I view http://localhost/flex2gateway/I get:
<head><title>JRun Servlet Error</title></head><h1>500 null</h1><body>
</body>
This is what is shown on the page. I have heard that it should be blank.
I can’t seem to figure out how to investigate what is wrong, somebody told me if I start ColdFusion using the terminal I will see all the errors when it loads. I thought that I can cd to
/Applications/JRun4/servers/cfusion/ and type start -cfusion but that did not work. Do you know how I can do this? If I can view the error, then maybe I can figure this out, and actually have flex and ColdFusion connect to each other.
Thanks so much,
John
HI Simeon,
I don’t think that anything with flex is loading.
I was able to find out how to start up using terminal & looked at the log.
I made a site here:
http://johnbarrett.net/cfusion/cfusion.cfm
Could you take a look at it? I made the errors on the log section in read. I just highlighted the "flex" stuff. I don’t think that it is working.
Thanks so much
Hey John,
Startup looks perfect. With that running try hitting http://localhost:8300/flex2gateway/
What do we get then? Actually! Make sure you are running CF 7.0.2 also. There was an updator for CF 7 that makes it work with flex. Your stuff might actually not be set up yet.
sim
HI Simeon,
Thanks so much for your help!
I re-installed the CF updater today, just in case. This did not help, and I get the same error.
I was able to upload the file to my shared hosting account and it works fine. They use Linux.I also tried today on a window machine (worked fine),and so I am thinking that the issue is getting it to work on the Mac system.
When I go to http://localhost:8300/flex2gateway/ I get 500 null. Just the text. When I go to http://localhost/flex2gateway/ I get 500 null, but with all the html tags. I know that it should be blank, but either way it is not.
If you go to
http://johnbarrett.net/cfusion/error.cfm you can see the error that I am getting, and there is a link to the file on-line click on remotingExample or the direct link is at:
http://johnbarrett.net/remotingExample/remotingExample.swf
I am going to re-install ColdFusion tomorrow to see if that helps, if not I might have to buy the MacbookPro, and do flex on the windows side, but that is not how I want to use flex and ColdFusion. Before I do that I will buy Flex Builder to see if that does the trick.
I can’t tell you how badly I want flex & ColdFusion to communicate. I have been able to do a lot in flex, and now it is time to use them together.
Thanks so much for all your help, I really appreciate it very much:)
John
I only got started with flex 2 days ago, and this had me pulling my hair out. I’ve now got it working, thanks heaps! Just one other thing… I published all of the project files - should I do that, or are there some I can, or should leave out?
Well your sever is gonna need to have all your cf code there. But as for flex you only need to push up whats in the bin folder. Its a couple html and js files and then your swf file that is your application.
Hi Simeon,
Are you able to view these files on your local machine or do you have to copy the files to your server and then view them from server? I cannot seem to find my CFC files when viewing on my local machine.
I am looking for a solution to develop locally also viewing locally without having to FTP the Files up to the server or create an ANT AutoBuild from my CVS.
Any thoughts,
Rich
If you have ColdFusion 7.2 and Flex Builder 2 installed, just carefully follow the tutorial below, and you will be up and running ‘locally’ withing the hour!
https://admin.adobe.acrobat.com/_a295153/p60842493/