views:

607

answers:

3

I'm trying to use Flex Compile Time Constants to include the date and time the SWF was built (source control revision/timestamp such as SVN:Keywords is not sufficient for our needs, we need to know the actual build time, not the commit time).

I've tried using actionscript (like the documentation suggests you should be able to):

-define+=COMPILE::Timestamp,"new Date()"

But this gives "The initializer for a configuration value must be a compile time constant"

I've tried getting it to drop to shell and use the date command (using various single and double quote configurations), for example:

-define+=COMPILE::Timestamp,`date +%Y%m%d%H%M%S` 

I can only get it to work with simple strings and simple constant expressions (eg, I can do 4-2 and it'll be 2 at runtime. But I can't get it to do anything whose value wouldn't be explicitly known at the time I declare the define.

Has anyone had any luck with something like this?

A: 

The key to your problem is most likely in the following statement by Adobe referring to Compile Time Constants: The constant can be a Boolean, String, or Number, or an expression that can be evaluated in ActionScript at compile time.

I would assume that the Timestamp is not available at compile time.

However, you may try using a string instead (something like this)

public function GetUnixTime():String{
var myDate:Date = new Date();
var unixTime:Number = Math.round(myDate.getTime()/1000);
return unixTime.toString();
}

Another thought is that you could get the information from the compiled file.

Hope this helps.

Todd Moses
The "or an expression that can be evaluated in ActionScript at compile time" is what gave me hope, but even the simplest scenario I could conceive of (`-define+=COMPILE::Timestamp,"new Date()"`) doesn't work (nor does `new Date().toString()`). I did try creating a method like yours, but it gives the same error as stated above, "The initializer for a configuration value must be a compile time constant."
MightyE
Oh, also, the disk timestamp sort of defeats what I was trying to accomplish, which was to have the Flex client "just know" the date/time it was built (I'm a little surprised there aren't pre-supplied constants of this sort). To use the timestamp, we'd need something server-side to read the timestamp and report it back. This makes it dependent on the time and timezone of the server on which it's running, some specific server-side software, and particularly in error situations (part of what we want to do is include build time in error reports), this may fail on us.
MightyE
FWIW, a little background: This is a library which will be embedded in other applications. We can't necessarily guarantee that it will be running a particular server-side runtime, nor even necessarily that it's running in a web page, Air app, desktop app, phone widget, etc.
MightyE
+1  A: 

After extensive research, I've concluded that this simply isn't doable.

MightyE
A: 

If you don't use FlexBuilder to do your builds you can do it quite easily.

I do something like this with FlexMojos in Maven.

In the relevant config section:

                <definesDeclaration>
                    <property><name>BUILD::buildVersion</name><value>"${project.version}"</value></property>
                    <property><name>BUILD::buildRevision</name><value>"${buildNumber}"</value></property>
              <property><name>BUILD::buildTimestamp</name><value>"${timestamp}"</value></property>
                </definesDeclaration>

FlexBuilder pretty much sucks as a build environment for reasons like the one you mention