Often we find there are situations where we wish to use an AS3 Library or Class in our Haxe project and it is not part of the core flash9 classes. There are several approaches either converting to Haxe or creating compiler information for Haxe the source ( swf or swc ).
You can either convert AS3 to Haxe manually, or use a converter that can help translate most of the code. Since AS3 and Haxe differ, it is not always possible to automatically convert all the code.
- as3hx Haxe converter. http://haxe.org/com/libs/as3hx
- Tarwin's Haxe neko script converter. Written in Haxe, still work in progress - Tarwins AS3 to Haxe conversion script.
(added 14 March 2011, last updated 10 April 2012)
[discontinued since February 2009]Convert the AS3 to Haxe using as3toHaxe, a converter written in haskell.
[discontinued since July 2009]Another converter available called Haxer is a AS3 to Haxe translator written in Java that includes full type refactoring, import statement expansion, and property conversion.
For the Haxe compiler to use AS3 classes without porting them, the compiler needs information about the classes' public methods etc.., these take the form of class 'Stub' files and allow compile checking.
- Stub files are used with Library swf's, See using the Library
- Stub files are used with loading a swf into the same application domain so that classes definitions can be added at run time. See 'Flash Application Domains' ( not yet created ).
To generate a stub file create a swf that imports and uses an instance of every class you need a stub file for. The swf used for stub class creation does not need to be the same as the Library or loaded swf. The compiler uses tag:
Where 'stub.swf' is the movie that contains instances of classes we need stubs from.
The compiler normally places Stub files in a subdirectory. We can use the stubs when compiling by pointing to the cp, or class path for the stubs ( always inside sub directory hxclasses ) and then use the classes with a libray movie ( could also be our stub movie ) or with a loaded ( into the same Application Domain ) movie. For example
-cp hxclasses -swf-lib lib.swf
we can do this all in a single compile file using the compiler '--next' but we often don't need to recreate stubs files.
--gen-hx-classes stub.swf --next -cp hxclasses -swf-lib lib.swf
To use Swc we currently unzip them to extract the swf and use them as both the Stub swf and the Library swf as described above, a detailed case is explain in this other tutorial aswingas3 example. The latest version of Haxe can use swc directly.