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 ).
There are four approaches to converting AS3 files none of them are complete.
- Convert the AS3 to Haxe using Tarwin's Haxe neko script, still work in progress but since it's Haxe I have added it directly to the bottom of this page.
( added 14 March 2011 )
- Convert the AS3 to Haxe using as3toHaxe, a converter written in haskell. However this is only a partial converter and still a lot of work by hand maybe required. Away3D used this approach.
To download the source as a zip file there is a 'download source' link on this source page (top right).
Binaries for windows and mac can be obtained from the as3tohaxe google group's file section.
- 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.
- Convert AS3 to Haxe manually, this is not always as hard as it may seem. FacebridgeX used this approach.
(Nov 20, 2009) I have tried as3tohaxe & Haxer - I've found the code as3tohaxe has produced has been easier to work with particularly with variable instantiation
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.