Flex Challenges for Flash IDE Devleopers

A post recalled myslef got frustrated last September, after several weeks honeymoon turning into Flex from Flash.

No doubt some developers from Flex community not easy to understand what’s the meaning when a Flash developer complaining (AS3 === AS3) = false, as the majority of Flex developers do not know too much about development in Flash IDE. The feeling of ’second class citizens’ for Flash developers in Flex development also could not make sense to some of them.

I would like to say, there’s no different AS3 language itself whatever Flash IDE or Flex, but the way of coding is wholly different and big changes for Flash developers when try to work with Flex.

Rapid application development

My favorite Flex blogger Yakov Fain had a Flex and Java book in 2006, Flex Builder was a ‘RAD tool’ in that book, but some months later, a new post said ‘Flex 2 is not a RAD tool‘ telling the real truth. He also questioned the usage of dominated Cairngorm framework for Flex applications. Despite of some questions like these, however, Flex development is target to RAD. Although even today, the question asked by bosses ‘how to make a complex Flex application fast, extendable, fast UI change, great usabilities for every components and views, largely reusable classes to fit for different structures, tested fully with agile methods fast and easily, less developers and hours’ still no one-fit-all answer, Flex teams are working the way into RAD at some percents.

The RAD nature of Flex making the big difference between Flash IDE applications and Flex applications, as Flash applications are more focus on Creative and User Experiences. Flash IDE projects are mostly like to be design-driven, with smooth workflow between designers and Flash IDE developers. While Flex application must largely adopt design patterns, restricted by components-base structure, agreement such as framework, patterns, coding style, between developers now and future.

Developing Flex applications, Flash IDE Developers have to learn more design patterns and structure frameworks, reading Flex SDK source code, get familiar with Flex components functions/events/behaviors, struggle with SDK bugs.

Design challenges

Early months before, I got impression from Adobe’s seminars/articles that, Flex framework is to give you a fast, powerful, extendable component-container collections, easy to change with CSS and bitmaps. And you can easily extend design with Flash IDE even. That’s not the truth in real world. That’s what talent Flash/Flex developer Jesse Warden talking about design challenges.

I used to have a former Flash IDE version of my Flex projects, everything could be replaced with Flex components except a creation task with script-based animations. I found it’s not too hard to move the code base from Flash project into new Flex application, and feel happy in the beginning. But later when my bosses asked me to change something from time to time, I got some pains the needs of strong-typed communication functions between Flex framework and that low-level UIComponent-extended Flash component, split my brain into two parts, one thinking in Flash another thinking in Flex.

Satisfaction

Most of workers working not only for money, but also for some sort of self-fulfillment, coming from satisfactions of his works. Flash IDE developers can get more or less satisfactions from Flash projects, where working with designers, whatever some sort of creatives and some sort of happiness.

Flash developers join into Flex projects will have less satisfactions. Each time when Adobe evangelist talking about how great a new Flex application is, someone will notice that ‘the best Flash applications in the industry still made with Flash IDE, not Flex’. Design challenges are limitations to make Flex to be satisfied like Flash applications, especially when designers have very limited experience working with Flex, even worse definitely no designer at all. Each time when the feeling comes, you ‘do not have the ability to make that happen which can be made with Flash easily’, can you feel it good?

Flex developers coming from Java or other languages getting satisfactions from Flex, as Flex applications he can build much beautiful than Java GUIs, HTML interfaces, and much easier. They’ve already have good experiences with enterprise design patterns, Flex is easy for them to dive into, and the results for them are amazing.

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: koch.zip .

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.

Binding

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.