Mat
Mat

Reputation: 567

Flash Builder conditional compilation problem

how can I do the following in a Flex project?

package{

#ifdef BAR
    class Foo{
        ...implementation of Foo....
    }

#else
    class Foo{
        ...alternative implementation of Foo
    }
#endif
}

if I try to do it with the following compiler statements -define CONFIG::BAR,true -define CONFIG::NOBAR,false

and program it this way:

package{

CONFIG::BAR{
    class Foo{
        ...implementation of Foo....
    }
}

CONFIG::NOBAR{
    class Foo{
        ...alternative implementation of Foo
    }
}
}

then flash builder gives me a compile error:

1018: Duplicate class definition: Main

how to resolve that?

Upvotes: 0

Views: 1104

Answers (2)

roberttdev
roberttdev

Reputation: 46633

Generally, if you want to do something like this, instead of defining the class two different ways, you would define two different subclasses of the same class (or two different classes implementing the same interface, if needed). Then inside your #ifdef clause, you would assign the correct subclass to a reference variable. Then the rest of the classes will reference that variable, and get to the class definition you want.

Upvotes: -2

Gerhard Schlager
Gerhard Schlager

Reputation: 3155

Take a look at Using conditional compilation. It looks like you don't need to put the class in a { } block.

If the documentation is right this should work:

package{

    CONFIG::BAR
    class Foo{
        ...implementation of Foo....
    }

    CONFIG::NOBAR
    class Foo{
        ...alternative implementation of Foo
    }
}

Upvotes: 4

Related Questions