Why haXe to SWC is important for Flex/Flash Developers?
I believe that haXe is the right platform for developing api’s and code libraries.
If you use just the haXe core libraries.
- Can compile to Flash 6-8 by generating a single
- Can compile to Flash 9-10 / Tamarin by generating a single
- generate optimized integer arithmetic
- autocast when reading typed arrays
- Can compile to NekoVM by generating a singl
- can be run from the commandline
- can be run on Apache Web server (with mod_neko or mod_tora)
- Can compile to AS3 source code
- Can compile to PHP 5
Making it ideal as write once and use it in many platforms solution.
Why HaXe to SWC?
Adobe has an initiative called alchemy which is a research project and tool chain that allows users to compile C and C++ code that is targeted to run on the open source ActionScript virtual machine (AVM2). The C/C++ code is compiled to ActionScript 3.0 as a SWF or SWC that runs on Adobe Flash Player 10 or Adobe AIR 1.5. Alchemy is intended to be used with existing C/C++ libraries that have few OS dependencies.¬†
Code generated by it will be much more optimized (for speed) and will run considerably faster than AS3 compiled byte code because compiling with LLVM tools (included as part of Alchemy) allows compile and link time optimizations to be applied that the ActionScript compiler does not use as yet. In addition, for operations involving ByteArrays there are opcodes that are optimized for performance, which the ActionScript compiler does not generate today. these opcodes exposes a special api which allows a byte array to be used as memory for the c, c++ code which bypasses the garbage collection mechanism, thus adding to the speed
HaXe can bring the same advantages for libraries that are yet to be written. It gives you the freedom of using all of the flash (10) specific api if you are not planing to use it in other platforms. It already supports the special opcodes that are used by alchemy and does lot of byte code optimization. Even though it is already capable of generating AS3 code, compiling it using mxmlc or compc will loose most of the advantages that are provided by the haXe compiler.
Let me list the advantages that the haXe compiler provides us
- In-line Methods and Variables
- Runtime Type Information
- Optimized Generics (for Flash9, 10)
- External File Resources
- Conditional Compilation
- Flash virtual memory API (made available in Flash player 10 and used exclusively by alchemy)
We can compile the final swf using haXe. While doing so we can incorporate our flex swf as well, but this will need this new workflow every time you need to modify and compile your flex application
So, ideal solution is to have haXe to swc compiler which compiles the libraries with all the optimization benefits it can give us and then we use the swc like any other compc or alchemy compiled swc in our flex/flash project.
We get best of both worlds
I’m very happy to say that we are very near to this dream. Thanks to Nicolas Cannasse, haXe to SWC is already made possible with the latest version of haXe which is available in the CVS repository. You may follow this thread to know more on the progress