Is it possible to do a #define in Adobe Flex?
Asked Answered
V

2

6

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!

Viridissa answered 26/3, 2010 at 23:59 Comment(0)
S
11

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);
        }
    }
}
Sapheaded answered 27/3, 2010 at 0:13 Comment(1)
Very cool. I didn't know you could do that! Thanks for the info.Threeply
S
2

Just to keep this info here, it is possible to use the C Pre-Processor (CPP) with AS3 if you want to. It provides more powerful features than the ones built into MXMLC, if you need them. Example:

http://osflash.org/flex2cpp

Sapheaded answered 29/3, 2010 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.