Learning Flex Part 3: Taming Cairngorm

Since I'm learning Flex in preparation for what will probably be a large project, I thought it would be smart to also tackle learning Cairngorm. In case you don't know, Cairngorm is a framework (they call it a Microarchitecture though I don't really see the distinction other than it sounds fancier) for creating RIAs with Flex.

I won't lie to you, Cairngorm is a monster. It seems much more complicated than any of the ColdFusion frameworks, even Mach-II which is arguably the most difficult for CF'ers to get their heads around. Maybe it's just been so long since I was on the outside trying to look in at a completely new language and framework, but at first glance Cairngorm looks ridiculously complicated.

Part of the challenge is simply trying to figure out where to start, get at good documentation, and get some examples up and running. I don't want to single out the Cairngorm people since this problem affects every framework I've ever seen, but they sure don't make it easy for a brand new person to come in and try to get a handle on how Cairngorm works or even where to start. Adobe.com has some detailed articles on Cairngorm, but even this just skip right over any kind of real introduction and leap right into detailed discussions of patterns and keeping state on the client, etc. All I wanted was two things: how do I actually SET THIS UP in FlexBuilder? And where can I see a non-trivial example of using Cairngorm with ColdFusion?

Luckily, with a lot of searching and some trial and error, I was able to answer both of these questions. I'll point out what I found and do some explaining here so that hopefully I can save future Cairngorm-seekers my pain!

The first really useful tutorials I found are at davidtucker.com. This guy understands how to explain something! Having the video and audio to go along with the tutorials is incredibly helpful. While he does sometimes fall into the "just trust me, do it like this because it is better" trap, overall these helped me understand how, and more importantly WHY, Cairngorm does things the way it does.

The second thing that helped me immensely was finding and running the ColdFusion-based port of the CairngormStore. The CairngormStore is a fairly complex store application based on the original Flex Store application (which in turn is based on the Store demo applications that are available for many frameworks and languages).

Even after I found this store though, getting it to run was actually quite a challenge for me. I downloaded the code and I then thought "OK, now what?" Here's how you get it working:

  1. Download the CF CairngormStore
  2. Create a new Flex Project in FlexBuilder (I'm using FlexBuilder 3). Make sure you choose a ColdFusion Flash Remoting project and ensure that the CF server settings work using the Test Configuration button. Also you can make life easier later by defining the main MXML file for this project as "CairngormStoreMultipleBackend.mxml"
  3. Also make sure you follow David Tucker's tutorial and add the Cairngorm .swc to your project's build path.
  4. Unzip everything from the zip file into temp folder.
  5. Copy everything under "/{your temp folder}/CairngormStoreMultipleBackend" into the "src" folder under your Flex project.
  6. Copy everything under "/{your temp folder}/CairngormStoreMultipleBackend/cfmx" into your ColdFusion web root (I'm using CF8).
  7. Go into the Flex project and find "/src/com/adobe/cairngorm/samples/store/business/Services.mxml" and comment out or remove the section that uses AMF0 and AMFPHP 1.2. Even though I'm not doing anything with PHP I could never get this to compile so I must be missing some AMFPHP bits.
  8. At this point everything should be set up. If everything is configured correctly, you should be able to cross your fingers and right click on your CairngormStoreMultipleBackend.mxml file and choose "Run as Flex Application". This will launch a new browser window and you'll see the CairngormStore.

Being able to run this example and move around through the code was very helpful to start getting a feel for how this beast of a framework actually works. However, be ready to feel overwhelmed. It is a LOT of code. It is a LOT of layers. Only as I experiment with it more and keep refactoring my simple Bookstore application over to Cairngorm do the pieces and layers start to make sense. I'll have some more follow ups on my experience with Cairngorm and Flex in general, but for now I think this is more than enough for any Flex neophytes to digest.

Quick Edit: I should also add that Brian Rinaldi's overview of Cairngorm in the last issue of Fusion Authority Quarterly Update was also quite helpful in explaining several of the layers in Cairngorm and walking though a simple example!

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Great post Brian! definitely this will save some time for cf flex guys who want to try a hand on Cairngorm framework.. Well what is your opinion about MG Version of Flex?
# Posted By shimju david | 12/17/07 12:03 PM
Thanks! I've looked briefly at MG:Flex but I don't think that Joe has plans to go much farther with it (I could be wrong though, Joe if you read this feel free to correct me). As I understand it, Joe has gotten more comfortable with how Cairngorm works and isn't sure it would be worth his time to try and build yet another Flex framework when there are so many other demands on his time (I hear changing diapers is a time-intensive process).
# Posted By Brian | 12/17/07 12:12 PM
Hi Brian,

Here are a few additional Cairngorm training resources:

CairngormDocs.org
http://cairngormdocs.org/

CairngormDocs.org is the Cairngorm community's primary repository for Cairngorm training resources.

Intro to Cairngorm -- Slides & Files from 360Flex Presentation
http://halcyonsolutions.net/presos/360flex/

Email support lists:

For users implementing Cairngorm:
http://groups.yahoo.com/group/cairngorm-documentat...

For developers extending Cairngorm:
http://tech.groups.yahoo.com/group/cairngorm-devel...

hth,

g
# Posted By greg h | 12/17/07 12:45 PM
Great post certainly helpful for learning flex.

@shimju david --- Check ColdBox for CF+FLEX based application
# Posted By Sam | 12/17/07 1:36 PM
You might want to take a look at PureMVC (http://www.puremvc.org), too. It seems to be the up and coming framework for flex and several other languages. I have to admit, though, that the way both frameworks package things up seems to go against most OOD ideas. The implementation aspects seem to take precedence over the business domain. It's not the end of the world of course, it just seems to bump into the way I think about this stuff.
# Posted By Mike Rankin | 12/17/07 4:28 PM
I am also picking up Flex/Cairngorm as time will allow. Here are some Cairngorm links I found useful.

Joe Rinehart's Cairngorm for ColdFusion/MG Developers: http://www.firemoss.com/blog/index.cfm?mode=entry&...

Eric J Feminella's Cairngen: Cairngorm code generator:
http://www.ericfeminella.com/blog/2007/01/04/intro...

CairngormFlex Assistant Project: (I haven't tried this one)
http://cairngormflex.sourceforge.net

Cairngorm-Documentation Yahoo Group:
http://tech.groups.yahoo.com/group/cairngorm-docum...
# Posted By Ray V | 12/18/07 11:25 AM
FYI, the reason the code in the Services.mxml that were connecting to PHP backend didn't compile is because they where using the RemoteObjectAMF0 class. You would have had to download that class from the site as well.
# Posted By Renaun Erickson | 12/31/07 11:24 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner