【问题标题】:AS3 conditional compilation for variables变量的 AS3 条件编译
【发布时间】:2015-03-15 11:23:13
【问题描述】:

我需要对 AS3 变量进行条件编译。

问题:

有没有办法在类级别进行 if-else 条件编译,使用单个编译参数?

详情:

这行得通:

CONFIG::DEBUG {
    public var myVar:int = 0;
}

但我需要 if-else 块(失败):

CONFIG::DEBUG {
    public var myVar:int = 0;
} else { // ERROR: no if for else...
    private var _myVar:int = 0;
    public function get myVar():int {
        return _myVar;
    }
}

我也不能在类级别使用有效的 if-else 块:

if (CONFIG::DEBUG) { //ERROR: can't have if statement at class scope.
   //debug stuff
} else {
   //release stuff
}

我可以使用 2 个参数,但我想避免它。

感谢您的宝贵时间。

【问题讨论】:

    标签: actionscript-3 conditional-compilation


    【解决方案1】:

    我认为您可以在不使用 else 的情况下这样做:

    CONFIG::debug
    // for debug purposes
    
    CONFIG::release
    // only for release version
    

    关于这方面的更多详细信息,您可以查看using conditional compilation、AS3 Conditional Compilation 和here。

    希望能有所帮助。

    【讨论】:

    • 感谢您的回答。所以我猜.. 1 编译参数是不可能的......
    【解决方案2】:

    我相信这可以通过以下方式实现:

    if (CONFIG::DEBUG == true) {
    //do something
    } else {
    //do something else
    }
    

    【讨论】:

    • 不在课堂级别。
    猜你喜欢
    • 2012-02-29
    • 2012-04-07
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 2012-06-07
    相关资源
    最近更新 更多