<switch>
Special syntax used to control compilation

Usage

Each <when> block which evaluates to true will include that block of code in the compilation. This provides a mechanism to conditionally include alternate blocks of code, depending on the value of compile-time constants.

The supported attributes for <when> are

  • <property>, which looks at a boolean compile time property: for example <when property="$as3"> checks for Boolean true.
  • <property> with <value>, checks that the given compile time property equals the given literal value: for example <when property="$runtime" value="swf9"> checks for string equality.
  • and, for back compatibility, the <runtime> attribute, equivalent to the above: <when runtime="swf9">.

The possible compile time constants are:

  • $runtime : string
  • $swf7 : boolean
  • $swf8 : boolean
  • $as2 : boolean
  • $swf9 : boolean
  • $swf10 : boolean
  • $as3 : boolean
  • $dhtml : boolean
  • $j2me : boolean
  • $svg : boolean
  • $js1 : boolean
  • $debug : boolean
  • $profile : boolean
  • $backtrace : boolean

The following examples show the use of the <with>, <unless>, and <otherwise> tags.

<canvas height="20" width="100%"> <switch> <when property="$dhtml"> <text>This program has been
            compiled for DHTML</text> </when> <otherwise>
            <text>This program has been compiled for SWF</text>
            </otherwise> </switch> </canvas>

You can also use <unless> in a similar way.

<canvas height="20" width="100%"> <switch> <unless property="$swf8"> <text>Not
            SWF8</text> </unless> <otherwise>
            <text>Must be SWF8</text> </otherwise>
            </switch> </canvas>