是否可以在 Adob​​e Flex 中执行 #define? [英] Is it possible to do a #define in Adobe Flex?

查看:30
本文介绍了是否可以在 Adob​​e Flex 中执行 #define?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我希望项目构建可以采用许多不同的路径,具体取决于是否已定义某些内容.flex 里有这种东西吗?

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

谢谢!

解决方案

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

查看此文档

示例 1:

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

CONFIG::debugging {//这里执行调试代码.}

示例 2:

根据您定义的是CONFIG::release"还是CONFIG::debugging"来更改按钮的颜色

//编译器/MyButton.as包裹  {导入 mx.controls.Button;配置::调试公共类 MyButton 扩展按钮 {公共函数 MyButton() {极好的();//将标签文本设置为蓝色.setStyle("颜色", 0x0000FF);}}配置::发布公共类 MyButton 扩展按钮 {公共函数 MyButton() {极好的();//将标签文本设置为红色.setStyle("颜色", 0xFF0000);}}}

I'm looking for a way to do something similar to a c/c++ #define in adobe flex.

I'd like to have lots of different paths a project build can take depending on wither or not something was defined. Does such a thing exist in flex?

I know there is ways to set global variables but that wont really suit my purpose. being able to have structures with numerous #ifndefined and such is really what i'm in need of.

thanks!

解决方案

Actually MXMLC (the compiler in the Flex SDK) does support some limited preprocessor features. You can use them to pass in constant values, or to simulate #ifdef / #ifndef type functionality.

Check out this documentation

Example 1:

This code only gets executed if the -define=CONFIG::debugging,true flag is passed to the compiler:

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

Example 2:

Change the color of the button depending on if you defined 'CONFIG::release' or '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);
        }
    }
}

这篇关于是否可以在 Adob​​e Flex 中执行 #define?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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