Can I make #define in Adobe Flex?

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

I would like to have many different paths that a project collection can perform depending on wilting or not defined. Is there such a thing in flex?

I know that there are ways to set global variables, but that really does not fit my purpose. being able to have structures with numerous #ifndefined, and this is really what I need.

thanks!

+6
flex preprocessor flex3
source share
2 answers

In fact, MXMLC (a compiler in the Flex SDK) supports some limited preprocessor functions. You can use them to transmit in constant values ​​or to simulate functionality like # ifdef / # ifndef.

Check out this documentation.

Example 1:

This code is only -define=CONFIG::debugging,true 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 whether you have defined "CONFIG :: release" or "CONFIG :: debug"

 // 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); } } } 
+11
source share

Just to save this information here, you can use the C Pre-Processor (CPP) with AS3 if you want. It provides more powerful features than those built into MXMLC if you need them. Example:

http://osflash.org/flex2cpp

+2
source share

All Articles