5
votes

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?

4

4 Answers

3
votes

I had the same problem and ended up using this blog post as a starting point. Worked really well for me. Just had to update a few bits of the class to flex 4. Pulled the date right out of the complied swf.

0
votes

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.

0
votes

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

0
votes

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