【问题标题】:Is it possible to do a #define in Adobe Flex?是否可以在 Adob​​e Flex 中进行#define?
【发布时间】:2011-02-01 10:09:29
【问题描述】:

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

我希望项目构建可以采用许多不同的路径,具体取决于是否定义了某些内容。 flex中是否存在这样的东西?

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

谢谢!

【问题讨论】:

    标签: apache-flex preprocessor flex3


    【解决方案1】:

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

    Check out this documentation

    示例 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);
            }
        }
    }
    

    【讨论】:

    • 非常酷。我不知道你能做到这一点!感谢您的信息。
    【解决方案2】:

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

    http://osflash.org/flex2cpp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多