来自http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_02.html:
“如果基类是 Sprite 或 MovieClip,则不能在纯 ActionScript 项目中使用 RSL。RSL 要求应用程序的基类(例如 Application 或 SimpleApplication)了解 RSL 加载。”
由于我的基类是 Sprite,所以我遇到了这个错误。
就我而言,最好使用以下步骤将所有必需的类编译到我的应用程序 swf 文件中:
- 使用 compc 创建一个 SWC,其中包含我想要包含在我的应用程序 swf 文件中的文件
- 将 mxmlc 与指向要包含的 SWC 文件的包含库一起使用。使用链接报告生成链接文件报告 (xml)
- 使用指向链接文件报告 (xml) 的 load-externs 编译每个附加的子 swf - 这不包括链接到 Application.swf 的文件被编译到每个子 swf
要实现第 1 步:
<!-- We define the global classes which will be compiled into the parent Application
swf, but excluded from the tool swfs. As pure actionscript projects with base
class of Sprite can't usually use RSLs, we are forcing these classes to be loaded
into the parent application, and excluded from the child applications, allowing an
"Rsl-like" optimisation -->
<fileset id="rsl.inclusions" dir="${main.src.loc}">
<include name="${main.src.loc}/path1/**/*.as"/>
<include name="${main.src.loc}/path2/**/*.as"/>
...
</fileset>
<pathconvert property="rsl.classes" pathsep=" " refid="rsl.inclusions">
<chainedmapper>
<globmapper from="${main.src.loc}\*" to="*"/>
<mapper type="package" from="*.as" to="*"/>
</chainedmapper>
</pathconvert>
<!-- Compile SWC -->
<compc output="${lib.loc}/MySwc.swc"
include-classes="${rsl.classes}">
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<source-path path-element="${main.src.loc}"/>
</compc>
要实现第 2 步:
<mxmlc file="${main.src.loc}/pathToApp/Application.as"
output="${bin.loc}/Application.swf"
debug="${debug}"
use-network="true"
link-report="WorkbenchLinkReport.xml"
fork="true">
<compiler.source-path path-element="${main.src.loc}" />
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<include-libraries dir="${lib.loc}" append="true">
<include name="MySwc.swc" />
</include-libraries>
</mxmlc>
要实现第 3 步:
<mxmlc file="${main.src.loc}/pathToChildSwf1/Child1.as"
output="${bin.loc}/Child1.swf"
debug="${debug}"
load-externs="WorkbenchLinkReport.xml"
fork="true">
<compiler.source-path path-element="${main.src.loc}" />
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
<compiler.headless-server>true</compiler.headless-server>
</mxmlc>
另一个方便的提示:使用 fork="true" 可以防止 Java VM 在编译许多 swf 时内存不足。
希望这有帮助!