Giving Cairngorm a Test Drive (Example Code)

As an application’s complexity increases, the ease of maintenance decreases. Heck, sometimes it gets harder to even extend an application with new functionality. I’ve been working on a Flex project in my free time for the last six months or so. It’s been getting pretty unwieldy lately, and I’ve had to juggle a few too many ugly details just to modify certain interactions. After a particularly frustrating night, I decided that I should finally take a break from my coding and check out Cairngorm.

For my first flying leap into this framework, I started by developing a simple search application based on the Yahoo! API Libraries for ActionScript 3. It displays web or image results in a list and allows you to move back or forward between pages. Nothing too complicated. I wanted to start with something a bit more complex than this Hello World example (written by Laura Arguello at ASFusion), but I needed to keep it simple enough that most of my focus would be on learning Cairngorm rather than designing the interface.

I had some trouble finding simple examples of Cairngorm out in the wild, and I found it a bit frustrating. If you’re new to Cairngorm, and you want to learn more, please right-click on the app to view the source code. I encourage you to focus on the MVC structure of the classes. However, please note that I didn’t spend a lot of time cleaning up the code for the user interface. In particular, there’s a messy item renderer on the search results list that I should have made into a proper class, and I’m sure I decided to skip a few other best practices. It should be useful enough, though.

About Josh Tynjala

Josh Tynjala is a frontend developer, open source contributor, bowler hat enthusiast, and karaoke addict. You might be familiar with his project, Feathers UI, an open source user interface library for Starling Framework that is included in the Adobe Gaming SDK.

Discussion

  1. Tangent

    Well, MVC is not a simple pattern, it took me a while to understand as well. ActionScript Cookbook would be a good place to understand the pattern, which would lend you a hand on understanding Cairngorm.

  2. Pingback: Code Sweat Blog » Blog Archive » Some Flex 2 Related Links (pt. one)

  3. mzx

    check me if im wrong but im looking for example with
    class ModelLocator:IModelLocator;
    any links?

  4. Josh Tynjala

    mzx, using the IModelLocator interface shouldn’t be any different than using the old-style ModelLocator interface that I was using in this example. If I remember correctly, when IModelLocator was introduced, I only had to change the name and everything else worked fine. The source code for my WordWeb app used IModelLocator if you really need an example.

  5. Sathya Moorthi K

    hi.. i need to retrieve all the table values from the database by flex+cairngorm using php+mysql.. need sample code.. help me.. please.. thanks in advance..