在Flex的,现在可以使用-define编译器选项做各种很酷的东西。 在我的计划,我现在用的选项,这样我的一些code被排除块这样的:
In Flex it is now possible to use the -define compiler option to do all sorts of cool stuff. In my program, I am using the option such that some of my code is excluded by blocks like this:
CONFIG::FACEBOOK{
//Some code
}
这是运作良好。
And this is working well.
我要如何使用MXML一个类似的行为?
How do I get a similar behaviour with MXML?
我想要做同样的事情,但省略/包括MXML标签这种方式,AS code不是块。
I want to do the same thing, but omitting/including MXML tags in this way, not blocks of AS code.
我的解决办法是添加一些标签,可以帮助注释掉MXML code块不必要的某些版本。 比如我想在Android中增加不同的按钮和iOS构建:
My solution is to add some tags that could help to comment out unnecessary blocks of mxml code in certain build. For example I want to add different buttons in Android and iOS builds:
<!-- iOS --><!--
<s:Button id="backBtn"
icon="{SHOW_LIST}"
click="navigator.popView()"/>
--><!-- /iOS -->
<!--Android-->
<s:Button id="exitBtn"
label="Exit"
click="NativeApplication.nativeApplication.exit()"/>
<!--/Android-->
现在运行简单的批处理脚本,将注释掉所有的Android特定的code源代码中为iOS打造
Now run simple batch script which will comment out all Android specific code in the source for iOS build
prepareForIos.cmd
@echo off
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!--Android-->" "<!-- Android --><!--"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!--/Android-->" "--><!-- /Android -->"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!-- iOS --><!--" "<!--iOS-->"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "--><!-- /iOS -->" "<!--/iOS-->"
pause
放屁是一个命令行工具,用于查找和替换字符串
FART is a command-line tool for finding and replacing strings
现在我们code看起来是这样的,并准备为iOS待建:
Now our code looks like this and is ready to be built for iOS:
<!--iOS-->
<s:Button id="backBtn"
icon="{SHOW_LIST}"
click="navigator.popView()"/>
<!--/iOS-->
<!-- Android --><!--
<s:Button id="exitBtn"
label="Exit"
click="NativeApplication.nativeApplication.exit()"/>
--><!-- /Android -->
逆操作批次:
Inverse operation batch:
prepareForAndroid.cmd
@echo off
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!--Android-->" "<!-- Android --><!--"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!--/Android-->" "--><!-- /Android -->"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "<!-- iOS --><!--" "<!--iOS-->"
"C:\Program Files (x86)\bin\fart.exe" -r -w -- H:\Flash\MyProject\src\* "--><!-- /iOS -->" "<!--/iOS-->"
pause