Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set static constants using conditional compilation?

Tags:

apache-flex

I am trying to set some public static constants on a class conditionally by passing variables to the compiler e.g. -define=CONFIG::ENVIRONMENT,'testing_server'

This is what I'd like to do:

if(CONFIG::ENVIRONMENT=='production')
    public static const DOMAIN:String="production_site.com";
else if(CONFIG::ENVIRONMENT=='testing_server')
    public static const DOMAIN:String="secret_domain.com";

I have tried many versions of this code, but everything so far has produced an error of one sort or another. The only way I have succeeded is by setting a compiler variable for each environment (all false except the one wanted which is true) and using the following syntax:

CONFIG::PRODUCTION{
    public static const DOMAIN:String="production_site.com";
}
CONFIG::TESTING_SERVER{
    public static const DOMAIN:String="secret_domain.com";
}

Obviously this means I have to tinker with long command line setting each time. I thought my initial approach was possible given the documentation and various tutorials I have read.

Can anyone help?

like image 652
cammil Avatar asked Mar 10 '26 18:03

cammil


1 Answers

One thing that has worked well for us in this situations is #include. Use the build script to generate a single line of AS which has the declaration. Then use #include to include the generated AS file in a class.

I wouldn't recommend widespread use of includes, they're ugly and can lead to problems, but very small usages can be useful in certain situations.

like image 170
Samuel Neff Avatar answered Mar 12 '26 09:03

Samuel Neff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!