Saturday, January 16, 2010

Invoking the Flex Compiler via Native Process API in AIR 2.0

AIR 2.0 comes with the ability to interact with native processes. This means we can launch a process from the AIR application and communicate with its standard input/output. However, applications using the native process api must be packaged into native installer. Therefore, you must compile it separately in Windows, Mac and Linux to get 3 files as compared with 1 AIR file for all platforms.

Working the Native Process API is fairly easy. All the operations are performed using the NativeProcess class. To start a native process, you have to call the start method. The parameter passed to the start method is of type NativeProcessStartupInfo. This basically is used to represent the location of the process to be started and also to specify arguments(if any) for the process. I've created a very simple application which uses the Flex compiler (mxmlc) to compile an application.

First off, according to the Developer FAQ at Adobe Labs , bat files cannot be directly launched. Instead we launch the command prompt and then pass the command as input. Once a native process has started, we can write to its input and read from its output by using the standardInput and standardOutput objects. Here is a little screenshot of the application :

We get the location of the Flex SDK directory, the main application file and the output file. When the compile button is clicked, we create a compilation command using the three data (eg : /bin/mxmlc /app.mxml /app.swf) and execute the command. When the output is received, we use the file.openWithDefaultApplication() property to run the SWF file.

While running the application from the native installer, the command prompt also opens up beside it (which does not occur when you run from within Flash Builder).
Also note that this example assumes your application file has no errors. This is just a proof-of-concept to show how easy it is to build an application like this.

Resources :
AIR 2 (Adobe Labs)
Interacting with a native process (Adobe AIR Developer Center)

Here are the source files for the application :
The FXP file
The compiled native installer .exe file (Windows only)

There are still concerns about updating applications using native installers as the update framework will not work with this. I'm definitely looking forward to more cool demos from the community.


  1. In my opinion if you really want to learn Flex, I would start with Adobe's "Adobe Flex 2(or 3 coming out soon): Training from the Source". I think its a great book for getting started and actually steps you through building a real world application. Lastly, if you are interested in Flex certification down the road much of the cert test questions are based on this book.

  2. Earn from Ur Website or Blog thr!


    Nice to e-meet you. A very warm greetings from PayOffers Publisher Team.

    I am Sanaya Publisher Development Manager @ PayOffers Publisher Team.

    I would like to introduce you and invite you to our platform, which is one of the fastest growing Indian Publisher Network.

    If you're looking for an excellent way to convert your Website / Blog visitors into revenue-generating customers, join the Publisher Network today!

    Why to join in Indian Publisher Network?

    * Highest payout Indian Lead, Sale, CPA, CPS, CPI Offers.
    * Only Publisher Network pays Weekly to Publishers.
    * Weekly payments trough Direct Bank Deposit, & Checks.
    * Referral payouts.
    * Best chance to make extra money from your website.

    Join and earn extra money from your Website / Blog

    If you have any questions in your mind please let us know and you can connect us on the mentioned email ID

    I’m looking forward to helping you generate record-breaking profits!

    Thanks for your time, hope to hear from you soon,
    The team at

  3. Great article with excellent idea! I appreciate your post. Thanks so much and let keep on sharing your stuffs.Tamil News