When compiling your SWC, you can specify compile constants by passing them in a -define
argument. This will however, only include whatever code you've added using that constant - i.e. you can't reset the const in a project that includes the SWC to get a different result.
Below is the code for a bat file for creating an SWC. Copy it into a new file, and save it with the extension .bat. Replace the file paths as necessary.
@echo off
set flexroot=D:\Program Files\FlashDevelop\Tools\flexsdk\
set proj=D:\Dev\TestSWC\
cd %flexroot%bin\
compc.exe -source-path %proj%src -is %proj%src -optimize -define CONFIG::debug false -define CONFIG::release true -output %proj%bin\TestSWC.swc
pause
I used this to build a SWC file containing a single class, like so:
package
{
public class TestClass
{
public function sayHello():void
{
CONFIG::debug
{
trace( "Hello debug" );
}
CONFIG::release
{
trace( "Hello release" );
}
}
}
}
I then created another project, included the SWC and set the CONFIG::debug flag to true
, and called the sayHello()
function. It traced "Hello release"
as the SWC was compiled with the CONFIG::release flag as true
.