Tips and Tricks
This is a collection of small things that you can tweak in the language or compiler flags in order to get specific behavior.
Compiler Flags
You can define a flag with -D flagname commandline parameter. Some flags produce an additional effect :
check-xml-proxy: tells at the end of compilation which fields of thehaxe.xml.Proxyare not useddump: will create a/dumpdirectory containing the dumped Haxe typed AST (for compiler debugging purposes or curious hackers)macrotimes: print per-macro execution time results (to use together with--times)no-compilation: generates Haxe/CPP code but does not compile itneko-source: generates.nekosource but does not compile it to.nno-swf-compress: disable SWF output compressionhaxe-boot: force the SWF boot class to be namedhaxeinstead ofboot_XXXX(automatic for SWC output)fdb: include the Debugger tag in SWF output and extra debug infos (enable interactive debugging of Flash content)network-sandbox: use the network sandbox flag for SWF outputswf-protected: by default the compiler turns allprivatefields aspublicin SWF output. This flag will keep them insteadprotected(AS3 protected == Haxe private)noEmbedJS: disable automatic-embedding of JS files in standard library (so far used by both js.SWFObject and js.JQuery)use_rtti_doc: enable macros to access field documentation / comments
Compiler Metadata
If a metadata identifier starts with :, then the corresponding metadata will not get generated at runtime. Instead, it might be use by the Haxe compiler internals to perform specific tasks. Here's a list of used metadata compiler identifiers :
@:require(xxx): will only allow to access the given field if thexxxcompiler condition variable is set (for instance with-D xxx). Can also be set on a whole class, in that case the class can still be referenced but all its statics and its constructor accesses are forbidden if thexxxvar is not set.@:final: the given class cannot be subclassed anymore@:hack: allow to subclass a class that was marked asfinal(use at your own risks)@:native("my.real.Path"): the given class (and all its accesses) will be compiled as if its real class path was the one given in parameter. This make it more easy to bind "extern" classes that might have a different name.@:core_api: identify this class as a "core api class". Its API will get checked against the abstract one declared in the Haxe standard library.@:fakeEnum(Type): tells Haxe compiler that this enum is just a collection of properties of givenType. In that case the compiler will not use enum switch for these, but instead classic switch. TheTypecan be used by the code generator backend to know actual field type (in general either String or Int)@:macroand@:build, see Macros@:keep: the given class or field will be preserved in the generated output even if never directly referenced (use it in conjunction with --dead-code-elimination)@:overload: see below@:extern static inline function foo() { ... }: this function will always be inlined but will not be generated as part of the resulting code new in 2.09
Flash Specific
In order to improve support for interacting with AS3 and Flash IDE, the following compiler metadata are available for Flash9+ platform only :
@:bind: when a class declared in Haxe withoutexternis already present in a SWF library, an error will be displayed. You can use@:bindbefore your class declaration to have it override the original SWF class declaration.@:bitmap("myfile.png") class MyFile extends flash.display.BitmapData {}: include a given bitmap file into the target SWF and associate it to MyFile class. The file is looked-up using the classpath.@:ns("namespace"): the specified field or method will be given this namespace@:protected: the specified field or method is marked as protected (used when overriding protected methods for instance)@:getter(x) function returnGetX() return 5: will generate a native getter on thexproperty. Please note that the methodreturnGetXno longer exists, so do not call it directly.@:setter(x) function setX( v : Float ) : Void { ... }: same as@:getter, but for setting the property.@:meta(Event(name="test",type="Foo")): generates the corresponding Flash metadata@:debug function foo() { .... }: force debug information to be generated for this method (even when compiled without-debug) new in 2.09@:nodebug function foo() { .... }: disable debug information for this method (even when compiled with-debug) new in 2.09
Overload
The @:overload metadata can be used when interfacing an external class method which arguments being of different types. You can declare the method in the following way :
@:overload(function(i:String):Bool{}) function foo( i : Int ) : Void;
You can have several overload declarations, the return type of the first one that is matched will be used.
Overload metadata is only useful for extern classes, it is most likely not usable for user-written Haxe classes.