2010-07-07 26 views
6

我想從哈德森傳遞到一個Flex應用程序的內部版本號。定義在行動腳本

我發現Adobe的文檔(http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html)在條件編譯看起來應該可以解決它,但我必須錯過一些東西。

所以在我的Ant構建文件,我有: -

<mxmlc 
     file="${app.dir}/${application.name}.mxml" 
     output="${dist.dir}/${application.name}.swf" 
     context-root="${application.name}" 
     debug="true" 
     locale="${locales}" 
     allow-source-path-overlap="true"> 
     <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/> 
     <compiler.library-path dir="${lib.dir}" append="true"> 
      <include name="*.swc" /> 
     </compiler.library-path> 
     <define name="BUILD::BuildNumber" value="'20100707.800'"/> 
     <source-path path-element="${src.dir}"/> 
     <source-path path-element="${cfg.dir}"/> 
     <source-path path-element="${locale.dir}" /> 
</mxmlc> 

然後我試圖檢索與

public static const buildNumber:String = BUILD::BuildNumber; 

但是編譯器與拒絕:

SomeModel.as(31): col: 47 Error: Access of undefined property BUILD.
[mxmlc] private static const _buildNumber:String = BUILD::BuildNumber;

有什麼建議麼?

+0

根據有關條件編譯的文檔;看起來你正在做的事情是完全正確的。我有點不知所措。 http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html。 Flex編譯器是否將您的公共靜態常量轉換爲帶有私有變量的getter/setter方法?這種轉換可能會導致這個問題? – JeffryHouser 2010-07-07 14:12:28

+0

可能。現在看來是直的。我可以在Flash Builder中使用它,在附加命令部分中使用 -define + = BUILD :: BuildNumber,'00000000.000' 。它只是不會從ant mxmlc構建中傳遞。 – Decado 2010-07-08 08:16:15

回答

2

的其他建議組合在這裏似乎工作。

這應該在你的build.xml文件(它假定您的build.xml已經分配一個值這點之前BUILD_NUMBER):

<mxmlc> 
    ... 
    <define name="CONFIG::build" value="&quot;${BUILD_NUMBER}&quot;" /> 
    ...  
</mxmlc> 

注意使用&quot;沒有任何引號。還要注意,你可以在compc中使用這個語法。

然後ActionScript代碼可以有這樣的事情:

public static const buildNumber:String = CONFIG::build; 

我不認爲你一定需要使用配置的命名空間,但它是一個通用的慣例。

0

有由LaurynasStančikas說你應該使用&quot;評論:

To pass string with Ant (when using mxmlc task), use &quot; . For example:

<compiler.define name="NAMES::AppName" value="&quot;'FooBar'&quot;" /> 

你試過了嗎?

+0

我試過這個。然而,它是無效的,螞蟻抱怨說,你不能同時輸入'和" ... – Decado 2010-07-08 08:13:49

0

我只是解決了一個JavaScript的flashvars問題,報價,這激發了 「試試這個」 的想法:

嘗試逃脫:

< compiler.define名稱= 「名字:: AppName的」 值=「\ 'FooBar \'「/ >

+0

剛剛發現了有關條件編譯的最新文檔,Adobe顯示了類似的內容。他們主要是顯示命令行參數,但也許轉義序列會通過ant。請參閱http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7abd.html上的「傳遞字符串」 – 2010-07-16 15:49:23

1

這絕對是一個引用問題。我打了很久。但是,我使用ant中的標籤運行mxmlc和compc,因此不確定我的分辨率是否相同。這當然對我的作品壽:

<arg value="-define+=ENV::build,&quot;${build.id}&quot;" /> 
<arg value="-define+=ENV::version,&quot;${build.version}&quot;" /> 

我可以建議你試試:

<define name="BUILD::BuildNumber" value="&quot;20100707.800&quot;"/>