Flex, AIR Projects without Flex, Part 1
Flex, AIR Projects without Flex, Part 1, Posted in General, August 15th, 2010

MXML is a great markup language. It is getting more extensible all the time and, often, is something you want to use in non-flex projects. In order to provide complete understanding on how to build MXML web and desktop applications ( Adobe AIR ) without the Flex framework; I am embarking on this multi-part journey to divulge the inner workings of Flex and AIR.

Flash Builder ( i.e. Flex Builder ) provides a very convenient wrapper and configuration for building Flex and AIR applications. It does not allow, by code-hinting, extending a non IUIComponent or UIComponent object in MXML e.g. <l:Sprite /> . So we do this with a little trickery.

After creating your default application ( be it either Flex or AIR ) you will need to create a ActionScript main file. Unlike other languages, the main in ActionScript becomes implemented at the flash.display.Stage and all of your other assets build from there. I tend to call this class Main.as, it can be placed anywhere in the source folder. Next you will have to manually change the “Default Application” MXML file to extend your Main.as. This is simply done by adding the namespace xmlns:local=”*” ( whereas * is the same package the Main exists in ). Then change <s:WindowedApplication /> or <s:Application/> to <local:Main />. The application should compile without errors.

Note, however, nothing displays on the screen. I usually add a trace statement in the Main constructor that allows me to verify that everything just started ok.

The ability to inject code at the stage level easily allows for not only bootstrapping of Pure ActionScript projects but also the ability to do a variety of tasks before starting Flex at all. Some instances, this may be a dependency checker/updater of some kind. In AIR, this could be a splash screen or some other useful action.

Here is a Zip file containing an example AIR application.
NoFlexAir.zip

Thats it for the first post, hope it was helpful. My email is at the top of this page if you have any questions.

P.S.
Using the non-system-chrome takes a lot of resources and essentially allows draw space over your entire screen estate. I have a inkling that the Popup / Context Components draw in some super-layer however I will cover that in another post.