views:

36

answers:

1

I am trying to use the "define" mxmlc compiler option to embed compile-time constants into my SWF files.

<mxmlc ...>
    <define name="NAMES::PluginCompileTime" value="Hello World!"/>
</mxmlc>

I can access this variable if I "hardcode" it into my codebase, as so:

public static const PLUGIN_COMPILED_TIME:String = NAMES::PluginCompileTime;

However, I would like to be able to do this at runtime using something like getDefinitionByName():

var value:* = flash.utils.getDefinitionByName("NAMES::PluginCompileTime");

This throws the following error:

ReferenceError: Error #1065: Variable PluginCompileTime is not defined.

Does anyone know of a way to accomplish loading a compile-time constant in a namespace at runtime?

+1  A: 

Compile-time constants aren't available at runtime. They're only available at compile-time.

If you need its value as a namespace const, then the correct solution is to "hardcode" it as you've done.

Gunslinger47
Thanks :) I guess I just kind of hoped that it would be possible to look it up as if it were a definition in the SWF file.
TK Kocheran
@tkk: I'm wondering why you need to do this. If you ever need the value at any point in your code, you can just write `var something:String = NAMES::PluginCompileTime;`. I can't see why you'd need an explicit copy of the value in a namespace global.
Gunslinger47
Well, one reason would be that having to hardcode the value in there introduces a compile time dependency to the codebase. If I don't have to hardcode, default values can be used instead, making my compile a little more "variable." :)
TK Kocheran