Using Flex, created a desktop and web application in that used conditional compilation. It runs successfully. Now, I Would like to have the single swc file for both Desktop and web. So created the library project for satisfying that condition. While using conditional compilation in flex library project getting many issues like conflicts variable name and duplicate functions and so on, which I haven't faced while using flex projects without swc file.

So the question arises now: Is it possible to have conditional compilation on a flex library project?

有帮助吗?

解决方案

When compiling your SWC, you can specify compile constants by passing them in a -define argument. This will however, only include whatever code you've added using that constant - i.e. you can't reset the const in a project that includes the SWC to get a different result.

Below is the code for a bat file for creating an SWC. Copy it into a new file, and save it with the extension .bat. Replace the file paths as necessary.

@echo off

set flexroot=D:\Program Files\FlashDevelop\Tools\flexsdk\
set proj=D:\Dev\TestSWC\

cd %flexroot%bin\
compc.exe -source-path %proj%src -is %proj%src -optimize -define CONFIG::debug false -define CONFIG::release true -output %proj%bin\TestSWC.swc

pause

I used this to build a SWC file containing a single class, like so:

package  
{
    public class TestClass
    {

        public function sayHello():void 
        {
            CONFIG::debug
            {
                trace( "Hello debug" );
            }
            CONFIG::release
            {
                trace( "Hello release" );
            }
        }

    }

}

I then created another project, included the SWC and set the CONFIG::debug flag to true, and called the sayHello() function. It traced "Hello release" as the SWC was compiled with the CONFIG::release flag as true.

其他提示

Quoting the docs:

The mxmlc compiler lets you pass the values of constants to the application at compile time

It does not mention compc, so I'm pretty sure it is not possible. I also wonder how that would work technically since you include/exclude parts of the code during compilation. The compiled SWC would no longer contain the conditional code.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top