Haxe AS3 Code Generator

Haxe has its own native Flash9 compiler, but there are some cases where you want to deliver AS3 source code to either your company clients or people not using Haxe. In that case, Haxe enables you to generate the complete corresponding AS3 source code from a set of Haxe classes.

Instead of using :

haxe -swf-version 9 -swf output.swf .....

Simply write :

haxe -as3 as3_src ....

This will generate all AS3 classes in the as3_src directory.
If you are using -main, it will also generate an as3_src/__main__.as class that will execute the program entry point.

To compile the generated AS3 Source code, simply use the MXMLC commandline program available as part of the free Flex2 SDK :

  cd as3_src
  mxmlc -output as3.swf __main__.as


There are not so many incompatibilities, only the ones that you should know when using Flash9 compared to using Flash 6-7-8.

In particular, the Int, Float and Bool values in Haxe are allowed to be null, while this is not the case in AS3/Flash9. If you still want to use null values (for example when having optional parameters for one of these three types), you will have to change the type to Null<Int>, Null<Float> or Null<Bool>.

This will inform Haxe that the Flash9 value type can be null. You can safely assign an Int to a Null<Int>, but assigning a Null<Int> to Int will convert null to 0, so you have to be careful to test for null first. Null values are converted to the * Flash9 type, so making calculs on them is significantly slower than basic types.


If you experience any problem with the AS3 code generator, please try to make a small example reproducing the problem and send it to the Haxe list. The problem should be fixed very quickly.

version #5566, modified 2009-03-14 16:32:28 by adnez