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:
- Download the CF CairngormStore
- 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"
- Also make sure you follow David Tucker's tutorial and add the Cairngorm .swc to your project's build path.
- Unzip everything from the zip file into temp folder.
- Copy everything under "/{your temp folder}/CairngormStoreMultipleBackend" into the "src" folder under your Flex project.
- Copy everything under "/{your temp folder}/CairngormStoreMultipleBackend/cfmx" into your ColdFusion web root (I'm using CF8).
- 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.
- 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!




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
@shimju david --- Check ColdBox for CF+FLEX based application
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...