Yesterday I released an AIR application that lets you browser CFLib.org from your desktop. This application didn't take terribly long - except for some issues I ran into with the new security model.
Today I thought I'd try it with Flex. I'm a bit rusty with Flex but I figured it couldn't be too hard. Turns out I was right. With some help from Scott Stroz and Simeon Bateman, I was able to crank out the application in a lunch break.
The only part that confused me was - how do I use RemoteObject to talk to a CFC on another server, which AIR allows? Turns out you just need to get a copy of CF's services-config.xml file. I placed it in my Flex app and added this to my compile args:
-services libs/services-config.xml
Next, I edited the file to change
<endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/>
to
<endpoint uri="http://www.cflib.org:80/flex2gateway/" class="flex.messaging.endpoints.AMFEndpoint"/>
That's it. I guess it really isn't much of an AIR app. It doesn't detect online/offline. But I find it cool that it took me 1/5th the time and came out ten times prettier. I've included the AIR app as a download. I renamed it to cflib.zip as I'm too lazy to mess with IIS settings. Rename it and run. If you ran the demo from yesterday, the installer will complain that an application with the same name exists. Either uninstall the other one or supply a custom install location.
Also - I used Flex Builder's Include Source option so you can see my ugly MXML code. Awesome.
Archived Comments
I played with AIR about 3 months ago and i did not have to do this to access a CFC on server.
I dont pretend to know Flex/AIR yet, so im curious if Flex/AIR has changed or was it the way i setup my RemoteObject tag? I used a attribute called endpoint and i noticed you did not in your code.
<mx:RemoteObject id="roGetJob" destination="ColdFusion" source="test" endpoint="http://demo.dev/flex2gateway/"
result="onGetJobResult(event)" fault="onGetJobFault(event)">
<mx:method name="getJob">
<mx:arguments>
<jobNum>{jobNum.text}</jobNum>
</mx:arguments>
</mx:method>
</mx:RemoteObject>
Is there a best practice on defining the endpoint?
Chad, I'm rusty in Flex, and definitely new to AIR. I may have missed the obvious. Try hitting my CFC like I did, see if it works. I mean, my address, your code.
Thanks Ray. Just tried to download your Zip and it does not seems to open. I have 7-Zip, you didn't use anything special to archive this app? Most probably a problem my end but thought I'd ask.
Cheers.
Notice I said, "I renamed it to cflib.zip as I'm too lazy..."
Just rename to .air. :)
When I tried this, I got an error when I hit build.
Error: Cannot assign operations into an RPC Service (endpost)
Wait, ignore that, I used the wrong property name. Trying again...
Wow, that worked like a charm! I'll ping Simeon to let him know as well. This is a LOT easier. To my other readers, I won't bother updating the AIR unless I release a new version.
Oh good, im glad that works.
I went to try it on my side and realized my eclipse/AIR setup is all messed up. I try to execute a compiled AIR app out of my eclipse and i get an error about it requires a version of AIR that is no longer supported.
I think i just need to upgrade to the latest beta AIR.
Oh... one more comment that i learned when playing with this stuff.
Im pretty sure it was the endpoint, but, it is case sensitive. If i remember right i camel cased it (Flex2Gateway) and beat my head against the proverbial wall trying to figure out what was wrong. You would think if my IIS is not case sensitive on the URL that the endpoint would not be also.
Also why name it flex2gateway? Im sure flex 2 is not going to be the last version. :)
Or is it meant to be Flex-Too-Gateway not version 2?
@Chad,
I think the way you mention is completely fine. The only thing I usually end up doing is handling most of it via actionscript instead of in the MXML, but that's all down to personal preference. If you're going to be using an MVC approach, I think it would make things easier to put it in actionscript in order to separate the view from the other components, but for a quick app, I think it works nicely :) I'm still reading up on all the blogs and articles for best practices, but I think that's still a work-in-progress :D
One thing I hope people realize - my Flex code is definitely NOT best practices. ;)
I was searching on how to connect to a cfc from flex and stumbled upon this. I tried to run the AIR app, but no dice.
"This application requires a version of Adobe AIR which is no longer supported. Please contact the application author for an updated version."
I guess my code is too old to run with the current version. I'll have to see if I can rebuild it.
I updated the code and it should work now in AIR 1.
hehe, now i get
"The application could not be installed because the AIR file is damaged. Try obtaining a new AIR file from the application author."