Flex 3/AIR version of CFLib demo

This post is more than 2 years old.

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.

Download attached file.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Chad posted on 12/20/2007 at 3:09 AM

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?

Comment 2 by Raymond Camden posted on 12/20/2007 at 3:16 AM

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.

Comment 3 by Steve Glachan posted on 12/20/2007 at 3:19 AM

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.

Comment 4 by Raymond Camden posted on 12/20/2007 at 3:24 AM

Notice I said, "I renamed it to cflib.zip as I'm too lazy..."

Just rename to .air. :)

Comment 5 by Raymond Camden posted on 12/20/2007 at 3:26 AM

When I tried this, I got an error when I hit build.

Error: Cannot assign operations into an RPC Service (endpost)

Comment 6 by Raymond Camden posted on 12/20/2007 at 3:26 AM

Wait, ignore that, I used the wrong property name. Trying again...

Comment 7 by Raymond Camden posted on 12/20/2007 at 3:28 AM

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.

Comment 8 by Chad posted on 12/20/2007 at 3:40 AM

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.

Comment 9 by Chad posted on 12/20/2007 at 3:55 AM

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?

Comment 10 by Gareth posted on 12/20/2007 at 7:04 AM

@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

Comment 11 by Raymond Camden posted on 12/20/2007 at 7:38 AM

One thing I hope people realize - my Flex code is definitely NOT best practices. ;)

Comment 12 by Derek posted on 6/2/2008 at 11:18 AM

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."

Comment 13 by Raymond Camden posted on 6/2/2008 at 3:47 PM

I guess my code is too old to run with the current version. I'll have to see if I can rebuild it.

Comment 14 by Raymond Camden posted on 6/2/2008 at 6:04 PM

I updated the code and it should work now in AIR 1.

Comment 15 by Derek posted on 6/2/2008 at 9:22 PM

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."