Is it possible to set static constants using conditional compilation?

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

This is what I would 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 tried many versions of this code, but everything still caused an error of one kind or another. The only way I succeeded is to set the compiler variable for each environment (all false, except the required one, which is true) and use 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 that I have to go through a long command line setting each time. I thought that my initial approach was possible based on the documentation and various tutorials that I read.

Can anyone help?

+3
2

, , - #include. build script AS, . #include, AS .

, , .

+1

. - :

trace('appMode = ' + CONFIG::appMode); 
if (CONFIG::appMode == "dev" || CONFIG::appMode == "tst") { 
    // if dev or tst
} else {
    // if anything else
}

appMode fb4, " " Flex (project → properties → Flex Compiler). :

-define+=CONFIG::appMode,"'dev'"

/ dev.

!

0

Source: https://habr.com/ru/post/1758053/


All Articles