是否可以在编译时生成一个(常量)变量,从那时起它将始终在运行时保持不变。
例如,是否可以编写一段代码,根据编译时的当前日期生成版本号,但从那时起始终保持不变,即使在不同的日期,也只能在新版本时更改编译。
提前致谢,
Citiral。
答案 0 :(得分:2)
我使用像Apache ANT这样的外部工具来完成工作并对我的代码进行版本化:
<!--
Get the current date & time
-->
<tstamp>
<format property="build.time" pattern="dd/MM/yyyy hh:mm aa" locale="en,UK"/>
</tstamp>
然后我将它放入类路径之外的类中,并将其与类路径中的等效项交换(此处为我的Version.as类)
<!--
Copy the template file and replace %BUILDTIME%
-->
<copy file="src/Version.as" tofile="src/as/de/client/project/utils/Version.as" overwrite="true" />
<replace file="src/as/de/client/project/utils/Version.as" token="%BUILDTIME%" value="${build.time}" />
</target>
这是模板Version.as的内容,它将替换类路径中的Version.as类:
package de.client.project.utils
{
public class Version
{
public static const BUILD_TIME : String = "%BUILDTIME%";
}
}
然后你只需要在启动时跟踪代码中的常量:
trace("Version: " + Version.BUILD_TIME);
regards.Rob