0

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?

Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411

1 Answers1

1

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
  • 7,001
  • 2
  • 21
  • 29
  • 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. – Naftuli Kay Sep 16 '10 at 15:54
  • @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 Sep 16 '10 at 19:05
  • 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." :) – Naftuli Kay Sep 20 '10 at 00:04