Skip to content

Conditional compilation

Mark Knol edited this page Jun 23, 2015 · 19 revisions

Sometimes you need two builds to be slightly different. The quick and dirty way is to use the compiler preprocessor: The following example will compile foo() in html, and fuu() in Flash, and bar() in other platforms.

Syntax

#if html
   foo();
#elseif flash
   fuu();
#else 
   bar();
#end

Flambe specific options (flags)

Such flags are simply said, just booleans, which could be provided to the haxe compiler. When provided they are true, when not provided, the are false. In your .yaml file, you can add these flags like this haxe_flags: -D flambe_disable_webgl. You can also add own tags this way. Disclaimer: This list might not be complete.

Provided by Flambe

  • flash Activated when compiling using Flash target
  • js Activated when compiling using Javascript
  • html Activated when compiling Web build
  • air Activated when compiling Air build (iOS, Android)
  • android Activated when compiling Android
  • ios Activated when compiling iOS
  • firefox Activated when compiling Firefox build
  • debug Activated when compiling with flambe build --debug

Options for developers (provide these in yaml-file)

  • flambe_transparent for transparent canvas backgrounds, HTML only.
  • flambe_disable_html_retina to disable canvas DPI scaling.
  • flambe_disable_webgl Disables webGL when true, HTML only.
  • flambe_disable_canvas Disables 2d canvas when true, HTML only.
  • flambe_disable_autoresize Disables canvas auto fit to browser-size, HTML only.
  • flambe_html_audio_fix ?
  • flambe_disable_firefox_mp3 Disables MP3 for Firefox 27, more info here

Internal Flambe flags

  • flambe_keep_asserts
  • flambe_keep_logs
  • flambe_debug_text
  • flambe_debug_renderer
  • flambe_disable_reloading

Debug

If you are using FlashDevelop, in the top of the bar there is a 'debug/release' dropdown. This option affects the debug flag. So you can use this wisely to automatically hide debug information. In release build, the code inside this block does not even exist.

#if debug
   debugOnlyThing();
#end

More debugging topics can be found here: Debugging.

All Haxe specific flags:

In most cases you may not need this, but you can get a list of all haxe-language specific predefined flags. You can get this list by running this command: haxe --help-defines

More on Compiler Flags on haxe.org

Clone this wiki locally