条件编译“ else” [英] Conditional compilation "else"

查看:86
本文介绍了条件编译“ else”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AS3中,您可以将常量传递给编译器

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.");
}

我正在寻找#ifndef之类的东西,以便可以抵消调试并使用它有条件地添加发布代码。到目前为止,我找到的唯一解决方案是在Adobe的条件编译文档中。我的调试和发布配置是互斥的,我不喜欢同时具有DEBUG和RELEASE常量的想法。

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

在此先感谢:)

推荐答案

使用 if / else 构造: 死代码将被编译器删除 nd不会在运行时进行测试。您的swf文件中将只有一个版本的代码。

Use the if / else construct : the dead code will be removed by the compiler and it will not be tested at runtime. You will have only one version of your code in your swf.

如果不确定使用反编译器或转储工具来查看实际发生的情况。

If you are not sure use a decompiler or a dump tool to see what really happens.

http://apparat.googlecode.com/files/ dump.zip

http:// www。 swftools.org/

...

这篇关于条件编译“ else”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆