One of my first thoughts when Apollo came out was how to support parallel development. I would like to use Apollo to deploy my Flex applications on the web and as desktop applications. In this post I’ll show you a simple way to port your Flex application to Apollo.
Basically, the only difference between a Flex and an Apollo application is the root tag in the MXML,
Application in Flex and
ApolloApplication in Apollo (on a side note, if “Apollo” won’t be the official name of Apollo, is the API going to change, or will we have to live with the code name? Including specifics in an API is a typical architectural fallacy).
I have actually come up with two separate ideas on how to compile a simple Flex application as both a Flex compatible and an Apollo compatible SWF:
My first idea was to use XSL to transform the Flex application MXML to an Apollo MXML, but I decided it was a bit overkill. I’m still trying to find a good use case for XSL and MXML files – I know this is a solution looking for a problem, but it’s too interesting to ignore.
A better idea is to do some simple refactoring. What you do is that you change the
Application tag in you main MXML to a
Canvas tag, then you create two new files: “Application.xml” and “WebApplication.mxml” (or whatever you like). If your previous main MXML was called “Main.mxml” this is what the two new files should contain:
<Application xmlns="http://www.adobe.com/2006/mxml" xmlns:zm="*" width="100%" height="100%" > <zm:Main/>
<ApolloApplication xmlns="http://www.adobe.com/2006/mxml" xmlns:zm="*" width="100%" height="100%" > <zm:Main/>
Basically, you refactor your Flex application into a Flex component and use that component in both your Flex and Apollo applications.
Mind you, this tip is mostly useful when you want to have your application both on the web and be able to run it with Apollo. For applications that want to take advantage of the other things that Apollo offers, this is a little too simplistic.
I have some ideas in mind for how to support more complex variants of Flex-Apollo parallel development, but I’ll save them for a later post when I have thought them through and tested them out properly. Until then my tip is that you google for “dependency injection”.