6

我正在寻找一种在 adobe flex 中做类似于 ac/c++ #define 的方法。

我想有很多不同的路径项目构建可以根据枯萎或未定义的东西。flex中是否存在这样的事情?

我知道有一些方法可以设置全局变量,但这并不适合我的目的。能够拥有具有众多#ifndefined 的结构,这正是我所需要的。

谢谢!

4

2 回答 2

11

实际上 MXMLC(Flex SDK 中的编译器)确实支持一些有限的预处理器功能。您可以使用它们来传递常量值,或模拟#ifdef / #ifndef 类型功能。

查看此文档

示例 1:

-define=CONFIG::debugging,true仅当将标志传递给编译器时,才会执行此代码:

CONFIG::debugging {
    // Execute debugging code here.
}

示例 2:

根据您定义的 'CONFIG::release' 或 'CONFIG::debugging' 更改按钮的颜色

// compilers/MyButton.as
package  {
    import mx.controls.Button;

    CONFIG::debugging
    public class MyButton extends Button {    
        public function MyButton() {
            super();
            // Set the label text to blue.
            setStyle("color", 0x0000FF);
        }
    }

    CONFIG::release
    public class MyButton extends Button {    
        public function MyButton() {
            super();
            // Set the label text to red.
            setStyle("color", 0xFF0000);
        }
    }
}
于 2010-03-27T00:13:25.663 回答
2

只是为了在此处保留此信息,如果您愿意,可以将 C 预处理器 (CPP) 与 AS3 一起使用。如果您需要,它提供比 MXMLC 中内置的功能更强大的功能。例子:

http://osflash.org/flex2cpp

于 2010-03-29T16:10:27.060 回答