If I were making a drink called Flex it would be 2 parts component, one part language (MXML), one part compiler, and 3 parts Flash Player. As RIA frameworks go, Flex is a bit different.

Today I want to dive into the unique elements of Flex and highlight the things that I think are critically important to understand. In many cases the patterns that operate within Flex are largely misunderstood and once you see them, the whole framework becomes much easier to use and more powerful. Here we go:
Flex is a generative framework and within each stage of the compiler code and graphics are translated into lower level application behavior. Basically you put MXML and FXG in and the compiler translates this into lower level features that mesh with Flash Player internals. Lets start with the 4 basic stages of the MXMLC compiler:
Stage 1 – Translate MXML to ActionScript Classes
Stage 2 (NEW in FX4) – Translate FXG to either ActionScript or SWF Bytes
Stage 3 – Compile ActionScript to ABC (Actionscript Byte Code)
Stage 4 – Embed media, graphics, bytecode into SWF
Stage 1 & 2 are the generative stages of the compiler and provide the foundation for many features of Flex that are not available in ActionScript alone like data binding, @Embed[], generating event listeners, member naming, AS class generation, component instantiation, and layout management. As all MXML is translated to classes, any component in MXML becomes a member variable via the @id attribute. Additionally MXML generation handles all component creation and instantiation logic and even supports lazy instantiation (see @creationPolicy ).
One of the key features during MXML to ActionScript Class generation is data binding. Binding works by isolating expressions within {} pairs and generating getter/setters to detect property change via the observer pattern. When a value changes on the target, it uses the expression to calculate a value automatically. example:
What is very nice is that this code would take a ton of time to create and resuse reliably, yet leveraging code generation it seems easy and automatic.
Seeing is believing! Within your Flex project, I want you to add in a compiler flag “-keep” like so:

This flag tells the compiler not to delete the generated ActionScript classes within your project. This small flag lets you see inside the code generation in Flex. You will see a “generated” folder appear magically within your project and will find parallel ActionScript classes for all parts of your application. This feature exposes how your applications work internally and shows you that seemingly minor MXML changes result in lots more ActionScript.
Code generation is the lever within Flex and is the feature that I feel makes it so great. Why do I need to write tons of instantiation code when this can and should be generated consistently? In many ways this is raw productivity as it makes the language of creating RIA’s simpler and removes the tedium of low level details (without removing anything). The other benefit is that this methodology takes nothing away from the developer, nothing! You are free to instantiate your components in raw ActionScript as you see fit but MXML automates this for you. In essence you can mix AS and MXML classes and extend Flex into the framework you need. No it doesn’t do everything, what does, but it doesn’t prevent you from adding more in.
In Flex 4 there are 2 new features that leverage code generation, States and Flex Graphics. The new states syntax allows you to define state transitions much easier in that you now define them within dot notation using the state name on properties you need to change over time. The compiler then takes these calls and generates transitions between states within your application. Simply adding in a value is all you do like so:
This is key to much of the behavior within Flash Catalyst as a complete design tool. By just drawing you can edit and manage states with components or within components easily. Additionally feature support for @excludeFrom and @includIn are also supported to assist state management.
Flex Graphics add in a whole new graphics compiler into MXMLC and largely change the capability of Flex. Prior to FXG Flex has been largely dependent on the drawing API. Basically anytime Flex wanted to change a component state, it executed ActionScript based drawing instructions to draw a surface in Flash Player. In Flash Player 10 the drawing API was extended to support commands that were in sync with the full vector capability of Illustrator and the addition of persistent/editable drawing surfaces. Some FXG:
The first generation drawing API allowed you to draw graphics additively on a single canvas, the second generation allows you to modify the graphics that have already been drawn. The other way to draw is using Flash Players native renderer, SWFBytes. Prior to FXG any embedded SWF assets could use SWFBytes that came out of Flash Professional. To provide flexibility FXG can be rendered at runtime via the drawing API or depending on how graphics are using in the app (skins) they can be compiled directly to SWFBytes. Typically SWFBytes are 3x faster in rendering than the drawing API, so there is a big performance boost for skinning in Flex with the compiler additions around FXG. Within FXG there is a concept of binding where a graphic can be changed in value at runtime. The generational stages of the compiler support this feature so that you can rotate graphics uniquely or change color / filter values with precision. I haven’t said much about Flex Graphics but I really believe it is a groundbreaking change for Flex.
In summary, I feel that the generative aspects of the Flex compiler add the most value to the overall product. Development using either MXML or ActionScript interchangeably really opens many options for developers. You get the lever of code generation built into the framework itself adding some very compelling features (binding, event generation, etc). At the end of the day MXML is a high level language that removes the tedium from a developers workflow. Instead of working to instantiate components, I can focus on interaction and refine my applications productively. Long story short this is why I started using Flex in the first place and why I am still passionate about it as a development framework.
Cheers,
Ted