Archive for October, 2007

Koch curve AS3 experiment

A simple Koch curve experiment in AS3, port from Java version. Koch curve discovered by the Swedish mathematician Helge von Koch in 1904.

Origin Java code: Computer Graphics for Java Programmers by Leen Ammeraal and Kang Zhang

You can download AS3 source code to try: .

Cairngorm Or?

I picked up Cairngorm framework two weeks before as the requirements of my Flex projects changed for more flexibilities and Joe’s MVC blueprint structure I used no longer enough. Another reason was the excellent example network monitor came with the release of Flex Builder 3 beta 2. Last week some shouts suggested pureMVC as a better choice to Cairngorm framework. That’s good news for sure if pureMVC could really challenge the dominating Cairngorm framework.

I don’t have time and enough experiences to discuss these two frameworks, here just my early thoughts about Cairngorm.


The most interest point of Cairngorm framework, for me, is its usage of binding. I did not trained myself for Flex development but more comfortable with CS3 Flash Player classes, so I knew very few about Flex mx.binding and in the beginning I have only one week (actually two weeks and non-paid weekend/night to refactor several projects from Flash CS3, I should thanks for Joe’s MVC blueprint which I could use perfectly without any pain). When I began a new Flex project with Cairngorm framework this month, Cairngorm unlocked for me.

I faced a big challenge in Flex development for a long period, was to set values for components. The problem is, when a screen (such as a state inside a view, a child screen inside a ViewStack) was loaded, you cannot always set values for components in the time you want to, they might be ‘null or undefined object’ or else, or simply data models not ready for you. In my projects, almost all components values in a screen have to get from server at runtime, with several requests in parallel AND in sequence, some screens even will change states because of server data received, and WHEN those responses come back, unknown. So often when I was going to set a component such as this.screen.username.text = ‘something’, I got a RTE ‘a null or undefined object’, or other troubles. A few complex screens could make this problem more complicated, such as revisit a screen has some logic of data changes, I have to code very carefully, save/restore data in data models and worried about when I could update those data in the screen, use saved values or data from server, bored and frustrated.

Cairngorm use the built-in binding feature very smart. It stores data models as bindable properties which can be accessed with ModelLocater static class, and components’ values in a screen can be binded(watching I prefer to say) to these properties. A benefit of this, even these properties were null, it wouldn’t give a RTE on those components but simply display nothing. Once these properties were updated, maybe parsing responses from server, it will be displayed immediately on the screens. Simply, it make the Flex framework work for you.

Cairngorm Framework is not Prison

Although Cairngorm introduced a clear architecture for Flex projects, and it has been very popular for many companies as an agreement between developers in teamwork of Flex projects, one thing still true, it’s not everything about architecture. As you can see, from Cairngorm blogs, documentations and examples, you couldn’t get a full guide how to structure your own large applications with Cairngorm in one week.

I met some challenges when I tried to use Cairngorm events/commands/service structure, I googled quite a lot cases other developers experienced and their solutions(rare informations), I think in my case, to use events structure for a major parts of projects are not fit, but simply a stupid way. Using Joe’s MVC services/controller structure, I wrote only several classes with a large list of functions and they have been reused quite well. But if I rewrite them into events/commands, I will simply waste my days/weeks and introduce bugs. Design patterns are good to use, but overuse design patterns also not the deal. Design patterns should improve effectiveness now or later. Cairngorm framework is just an implementation of some design patterns, if you find some parts not fit your current project, you should try to find your own solutions with other patterns but not to be a prisoner of framework.

Or pureMVC?

I don’t have time to try pureMVC yet. I had a glance on pureMVC website and documents. One thing I not so agree with pureMVC’s goal is, a framework cannot be suitable both for Flash and Flex. I think a success Flex application framework must know quite well the Flex framework structures, get benefits from Flex framework itself, avoid some traps such as memory leaks. But a Flash framework will be a low-level framework of Flash platform to work directly with Flash player API, shouldn’t be the same as Flex project, should care more about Garbage collection optimization than Flex projects. We can use the same principles of MVC or others both in Flash and Flex projects, but not a single version of framework.