25.5节. 编译和部署使用RSL的Flex应用程序

25.5.1. 问题
我需要部署一个使用了一个或多个运行时共享库(RSL)的Flex程序。
25.5.2. 解决办法
在应用程序编译后使用external-library-path指定RSL的位置。
25.5.3. 讨论
当Flex程序初始化时,它需要知道所有需要的运行时共享库的位置。external-library-path包含了这些信息;把它传递给编译器,这样Flash Player就能在实例化组件或类之前马上加载RSL的字节而不需要加载一个独立的SWF。

在使用RSL文件前,你必须先创建一个RSL。RSL保存在应用程序运行期访问的SWC文件中。

SWC RSL文件由compc编译,SWF文件由mxmlc编译。为了让应用程序能用RSL,必须通过runtime-shared-libraries指定RSL的位置并传递给mxmlc编译器。在本例中,使用Ant编译SWC以及将使用该SWC的SWF,也就是说,我们将使用compc和mxmlc。在Ant将要使用的build.xml文件中,需要以变量的形式声明这两个编译器:
+展开
-XML
<property name="mxmlcvalue="C:\FlexSDK\bin\mxmlc.exe"/>
<property name="compcvalue="C:\FlexSDK\bin\compc.exe"/>

然后,使用compc编译应用程序将要访问的RSL,使用move任务将它放到application/rsl目录下:
+展开
-XML
<target name="compileRSL">
<exec executable="${compc}">
<arg line="-load-config+=rsl/configuration.xml" />
</exec>
<mkdir dir="application/rsl" />
<move file="example.swctodir="application/rsl" />
<unzip src="application/rsl/example.swcdest="application/rsl/" />
</target>

然后使用mxmlc编译SWF。注意我们将把一个名为configuration.xml的XML文件通过-loadconfig参数传递给编译器。该文件包含了应用程序的所有设置,包括RSL的位置:
+展开
-XML
<target name="compileApplication">
<exec executable="${mxmlc}">
<arg line="-load-config+=application/configuration.xml" />
</exec>
</target>
<target name="compileAlldepends="compileRSL,compileApplication">
</target>

注意两种命令行调用都使用包含运行时共享库路径的configuration.xml文件:
+展开
-XML
<flex-config>
<compiler>
<external-library-path>
<path-element>example.swc</path-element>
</external-library-path>
</compiler>
<file-specs>
<path-element>RSLClientTest.mxml</path-element>
</file-specs>
<runtime-shared-libraries>
<url>example.swf</url>
</runtime-shared-libraries>
</flex-config>

代替命令行调用mxmlc添加的external-library-path项:
mxmlc -external-library-path=example.swc
使用load-config把configuration.xml传递给编译器,每个设置都从这个XML文件中读取。

传递给compc类似下面的文件:
+展开
-XML
<flex-config>
<compiler>
<source-path>
<path-element>.</path-element>
</source-path>
</compiler>
<output>example.swc</output>
<include-classes>
<class>oreilly.cookbook.shared.*</class>
</include-classes>
</flex-config>

本例中的Ant文件完整内容如下:
+展开
-XML
<?xml version="1.0"?>
<project name="useRSLbasedir="./">
<property name="mxmlcvalue="C:\FlexSDK\bin\mxmlc.exe"/>
<property name="compcvalue="C:\FlexSDK\bin\compc.exe"/>
<target name="compileRSL">
<exec executable="${compc}">
<arg line="-load-config+=rsl/configuration.xml" />
</exec>
<mkdir dir="application/rsl" />
<move file="example.swctodir="application/rsl" />
<unzip src="application/rsl/example.swcdest="application/rsl/" />
</target>
<target name="compileApplication">
<exec executable="${mxmlc}">
<arg line="-load-config+=application/configuration.xml" />
</exec>
</target>
<target name="compileAlldepends="compileRSL,compileApplication">
</target>
</project>

加支付宝好友偷能量挖...


评论(0)网络
阅读(123)喜欢(0)flash/flex/fcs/AIR