Using/Exporting SWC Files
SWC files are similar to SWF files, actually they are ZIP files which contain the following files :
library.swf: the SWF file containing AVM2 bytecodecatalog.xml: an XML file describing dependencies between the classes so you can easily link only a part of the API provided by the SWC
Creating SWC with Haxe
In order to compile a .swc file instead of .swf, simply specify an output file which extension is .swc, for example haxe -swf mylib.swc MyLibClasses
If you want to make sure that your whole library is compiled into the SWC you can use the commandline parameter --macro include('mypackage'), that will include all the files declared in the given package and subpackages.
Note: when compiling to a SWC, classes statics initialization order might differ from when compiling to SWF.
Using a Haxe SWC in AS3
In order to use a Haxe-compiled SWC in AS3, you will first need to initialize the Haxe system before doing anything else, by calling :
haxe.init(mc);
mc is a MovieClip that will be stored into flash.Lib.current
Using a SWC/SWF in Haxe
Haxe does not currently support SWC linking. You'll first have to unzip the SWC to extract the library.swf and add it with -swf-lib library.swf to your compiler parameters. As a result, it means that if you're linking a SWC the whole content will be linked with your SWF, not only the part you are using.
Haxe3 supports SWC linking. You no longer need to unzip the swc file manually and can directly link it with -swf-lib library.swc
Accessing classes
Haxe will automatically extract the classes defined inside the SWF if they are not declared in your code, and build a Haxe-compatible type for each of these classes.
While most of the time this will not cause any problem, in some cases you might have to create patch files that contain some changes that you want to apply to the classes before they get generated this way.
Patch files
A patch file consists of several lines which modify existing class field types:
// Removes a class field from Haxe definition -flash.accessibility.Accessibility.new // Adds metadata to a given class @:require(flash10) flash.desktop.Clipboard // Adds metadata to a given class field @:require(flash10) flash.display.BitmapData.setVector // Modifies a given field type flash.display.DisplayObject.blendMode : BlendMode; // Modifies a static field type static flash.system.IME.conversionMode : IMEConversionMode; // Modifies all function parameters with this specific name flash.display.BitmapData.$blendMode : BlendMode; // Modifies a single function parameter ClassName.$functionName__parameterName : Type; // Convert a class made of statics vars into an Haxe enum enum flash.text.TextFieldAutoSize;
Most of these examples are taken from this patch file which is used to patch core flash definitions.
You can use a patch file with --macro patchTypes('patchFile')
hx Classes Generation
Instead of having a SWF and a patch file, you can instead provide a list of .hx files containing extern classes definitions. This class list can be generated from a SWF with the following command :
haxe -swf nothing.swf --no-output -swf-lib library.swf --gen-hx-classes
Using Haxe-compiled SWC from Haxe
Since a lot of type information (such as type parameters) is lost while compiling to SWF/SWC, you should provide a precompiled SWF + the .hx extern files generated with --gen-hx-classes (see upper paragraph)