ax4

Powerful ActionScript 3 to Haxe converter
https://github.com/Tutez64/ax4

To install, run:

haxelib install ax4 1.2.0 

See using Haxelib in Haxelib documentation for more information.

README.md

ax4

ax4 is an ActionScript 3 to Haxe converter that tries to be very smart and precise about rewriting code. To achieve that, it actually resembles the typical compiler a lot, so here's how it works:

  • parse AS3 modules into the ParseTree structure, containing all the syntactic information
  • load classes and signatures from the SWC libraries so we have the external type information
  • process ParseTree and build the TypedTree, resolving all imports and type references and assigning type to every piece of code
  • run a sequence of "filters" which analyze and re-write the TypedTree structures to adapt the code for Haxe
  • generate Haxe modules from the processed TypedTree

Disclaimer

ax4 is a fork of ax3, created by Dan Korostelev (nadako) at InnoGames, by way of another fork. I developed ax4 to make a fan-made native port of Dungeon Rampage (see Dungeon Rampage Haxe).

I may or may not continue to maintain ax4, and port other games in the future.

Quick start

1) Install

With a Java runtime and haxelib:

haxelib install ax4

To build it from source instead, see Quickstart.

2) Create a minimal config.json

{
  "src": "path/to/as3/src",
  "hxout": "path/to/haxe/out",
  "swc": [
    "path/to/playerglobal.swc"
  ]
}

3) Run conversion

haxelib run ax4 config.json

Documentation

Compat runtime

  • compat/ contains AS3 compatibility/runtime helpers used by generated Haxe code (ASAny, ASDictionary, XML helpers, etc.).
  • Converted code depends on this layer: with the haxelib install, add -lib ax4 to your Haxe build; otherwise copy compat/ with the copy option (see Quickstart).
  • compat-test/ contains tests for the compatibility layer itself and is not meant to be shipped with production output.
  • If you modify compat/, update compat-test/ and run:
npx haxe test-compat.hxml

Conversion Pipeline

The pipeline is implemented in src/ax4/Main.hx:

  1. Parse AS3 into ParseTree
  2. Load SWC externs/signatures
  3. Type into TypedTree
  4. Run rewrite filters
  5. Generate Haxe modules

Known limitations

  • The parser doesn't currently support ASI (automatic semicolon insertion). The only case where a semicolon can be omitted is the last expression of a block.
  • Only a small, most commonly used subset of E4X is supported. It's recommended to rewrite the unsupported things in AS3 sources to adapt it for conversion.
  • XML literals (<a>...</a>) are not supported: skipXmlLiterals comments them out as null.
  • Some forms stop the conversion, such as a case after default or a split with a limit.
Contributors
Tutez
Version
1.2.0
Published
6 days ago
License
MIT

All libraries are free

Every month, more than a thousand developers use Haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on GitHub!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on GitHub

⌂