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
This is a fork of ax3 and this other fork. My initial goal is to make a fully working (fan-made) Dungeon Rampage C++ version, after which I would like to convert another game and to keep this project alive, but since I'm doing it in my free time, this isn't a guarantee.
- Java runtime (to run
converter.jar) - Node.js + npm (for Lix-based Haxe toolchain setup)
npm i lix
npx lix download
npx haxe build.hxmlThis produces converter.jar.
{
"src": "path/to/as3/src",
"hxout": "path/to/haxe/out",
"swc": [
"path/to/playerglobal.swc"
]
}java -jar converter.jar config.json- Home
- Quickstart
- Config reference
- Config examples
- Differences from ax3
- Filters overview
- Troubleshooting
- Contributing
- GitHub wiki setup and sync
compat/contains AS3 compatibility/runtime helpers used by generated Haxe code (ASAny,ASDictionary, XML helpers, etc.).- In most real migrations, converted code depends on this layer. Plan to include/copy
compat/into your Haxe project. compat-test/contains tests for the compatibility layer itself and is not meant to be shipped with production output.- If you modify
compat/, updatecompat-test/and run:
npx haxe test-compat.hxmlThe pipeline is implemented in src/ax4/Main.hx:
- Parse AS3 into
ParseTree - Load SWC externs/signatures
- Type into
TypedTree - Run rewrite filters
- Generate Haxe modules
- 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.
Most of the TODOs are actually in the code, so look there too, but still:
- don't parse
*=as a single token when parsing signatures (fixa:*=bparsing without spaces) - add a "final-step" filter to remove redundant
TEHaxeRetypes too - rewrite
arr[arr.length] = valuetoarr.push(value) - generate "type patch" files for loaded SWCs, replacing
ObjectwithASObjectand*withASAny - review and cleanup
ASCompat- rework some things as static extensions (e.g. Vector/Array compat methods) - add some more empty ctors to work around HaxeFoundation/haxe#8531
- add configuration options for some things (like omitting type hints and
privatekeywords) - fix imports
- add imports for fully-qualified names that can come from
@haxe-type - remove duplicate imports (can happen when merging in out-of-package imports)
- maybe add
inlinefor arithmetic ops in static var inits where all operands are also static inline - remove
publicfrom@:inject/@:postConstruct/@:preDestroyas these should not really be part of public API