Alexey Zakhlestin's Blog

Programming for Mac and Web



Ok, here is something interesting. I was browsing looking for something related to flash/actionscript programming and ways of client-server interaction (remoting). After an hour or so, I found something called ”haXe“…

haXe is a “web oriented universal language”, which means, that you can write all the front-end and back-end stuff in haXe, and compile it to the target platform afterwards. Currently, there are three target-platforms: flash, javascript and neko byte-code (you can learn more about NekoVM here). It is a high-level object-oriented strong-typed language with a strict syntax. It supports anonymous local-functions and anonymous objects. Another great thing about haXe: it has type inference, which means, that one rarely needs to specify the type manually. The program will just “know” which type should be there. haXe doesn’t have multiple inheritance, but has support for interfaces and “class parameters” (which are similar to C++’s templates).

If you are into that stuff, you can check all the language reference. Some pieces are really-really interesting. It seems like haXe tries to take the pieces of both object-oriented and functional languages and makes an interesting mixture.

Now, some more practical stuff. As I mentioned, I found haXe, while looking for stuff related to flash programming. Using haXe, it is possible to write code in a language, which is more powerful than ActionScript-3.0 and compile it to swf, targetted to any flash-player version you like. You will still be limited by APIs which are bundled with that version of player, but the language itself is no more a limit. By the way, as a bonus, you get a bunch of powerful haXe’s apis, which are not available for usual actionscript developers.

haXe supports different kinds of remoting. It is possible to use flash’s AMF remoting, if you need to be compatible with that or native haXe remoting. Synchronous and asynchronous modes are available, of course, and it is also possible to use flash-javascript interaction. And, yes, I know you want to ask: you can do AJAX stuff in haXe too :)

You can download haXe here. It is precompiled for several platforms. It is trivial to compile it yourself, if you have ocaml compiler anywhere around (which is the case, if you use some kind of unix).

The usage is simple. Start with creating the following Test.hx:

    class Test {
        static function main() {
            trace("Hello World !");

Now, just issue the following command in the console: haxe -swf test.swf -main Test. You will have a working swf file which says ‘Hello’ to all the world :)