Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
733 views
in Technique[技术] by (71.8m points)

apache flex - Conditional compilation "else"

In AS3 you can pass a constant to the compiler

-define+=CONFIG::DEBUG,true

And use it for conditional compilation like so:

CONFIG::DEBUG {
   trace("This only gets compiled when debug is true.");
}

I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.

Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:

if (CONFIG::DEBUG) {
   //debug stuff
}
else {
   //release stuff
}

I also considered doing something like this but it's still not the elegant solution I was hoping for:

-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG

Thanks in advance :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works fine and will strip out code that won't run:

if (CONFIG::DEBUG) {
   //debug stuff
}
else {
   //release stuff
}

BUT this will be evaluated at runtime:

if (!CONFIG::DEBUG) {
   //release stuff
}
else {
   //debug stuff
}

mxmlc apparently can only evaluate a literal Boolean, and not any kind of expression, including a simple not.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...