0

Let's say I have to compile two different versions of my .swf for different sites. The difference is in hostnames for the ajax and redirection, several minor tweaks in code and in graphics added to the project in .swc. I can switch different swcs easily, but the code tweaks are hard to manage easily. I've got

CONFIG::site1 
{
    private var _domainName:String = "site1.com";
}

CONFIG::site2
{
    private var _domainName:String = "site2.com";
}

FB brings up an error: 1151: A conflict exists with definition _domainName in namespace internal.
What I need is smthn like this in C:

#ifdef SITE1
char hostname[] = "site1";
#endif

#ifdef SITE2
char hostname[] = "site2";
#endif

Is there any way to use compile directives that way using mxmlc?

P.S. Everything works now

Nanako
  • 337
  • 3
  • 14

3 Answers3

3

I think this documentation will help you.

In your case it is something like the following:

private var _domainName:String = NAMES::site;

And mxmlc arguments will look like:

-define+=NAMES::site,"'site1.com'"
Constantiner
  • 14,231
  • 4
  • 27
  • 34
  • That's what I've read before posting here. _in much the same way you would use an #IFDEF preprocessor command in C or C++. You cannot use constant Boolean values to conditionalize metadata or import statements._ Nothing about the variable declaration. – Nanako Aug 18 '11 at 13:07
  • That looks nice, thanks, but what about conditional compilation? It looks like mxmlc treats the CONFIG blocks like the general code, not separately. Is there any known way to bypass that? – Nanako Aug 18 '11 at 13:15
  • @Nanako Documentation is titled "Using conditional compilation" :) And the first code snippet in the documentation contains a sample of that :) – Constantiner Aug 18 '11 at 13:21
  • @Nanako you should define both parameters as Pavel said in comments to the question. – Constantiner Aug 18 '11 at 13:22
  • yeah, but the compiler shares the namespace between the code blocks, though it definetely shouldn't. That's my problem. :( – Nanako Aug 18 '11 at 13:24
  • But in your particular case there is no need in conditional compilation. See code from my answer which is better option for that. – Constantiner Aug 18 '11 at 13:24
  • Can't understand your problem. Did you defined command line parameters properly? – Constantiner Aug 18 '11 at 13:26
  • The problem was in FB somehow, I've restarted it and the problem was gone. Also I've replaced = with += in the command line parameters. – Nanako Aug 18 '11 at 13:28
  • Did you defined compiler parameters in Flash Builder properly? – Constantiner Aug 18 '11 at 13:29
  • -locale en_US -use-network=true -define+=CONFIG::site1,true -define+=CONFIG::site2,false – Nanako Aug 18 '11 at 13:31
  • Your compiler arguments and your code from the question works fine for me. Just checked it on a newly created project. – Constantiner Aug 18 '11 at 13:44
  • I've got the same problem once again. Flash Builder seems to cache swc, so if I change something within, especially the asset esported names, I have to restart FB, so it can find them. Reloading project, refreshing it -- nothin helps, only restarting the whole thing. – Nanako Aug 18 '11 at 14:42
0

You could do this :

private var _domainName:String = CONFIG::site1 ? "site1.com" : "site2.com";

If you want to know what's possible with configuration constants have a look at this page :
http://wiki.ecmascript.org/doku.php?id=proposals:program_configuration
So far I've found that the compiler support everything mentioned on this page.

cmann
  • 1,920
  • 4
  • 21
  • 33
0

Why code the domains at all? Not a directive or specifically an answer to your question I'm just saying lol

private var _domainName:String;

var lc:LocalConnection = new Local
this._domainName= lc.domain;
The_asMan
  • 6,364
  • 4
  • 23
  • 34