0

我创建了一个模块化应用程序,其中父 SWF 按需加载许多其他 SWF。为了优化,我创建了一个标准 RSL

我已将通用代码编译为 swc,并重新编译应用程序 swfs 以引用此 swc,在我的 build.xml ANT 任务中使用以下内容(对于我的应用程序中的每个 swf):

<static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
<runtime-shared-library-path path-element="${lib.loc}/RSL.swc">
    <url rsl-url="RSL.swf"/>
</runtime-shared-library-path>

我从 RSL.swc 中提取了 RSL.swf 并将其放在我的网络服务器上,与应用程序 swfs 和容器 html 文件位于同一目录中。

现在,当我加载我的应用程序时,我收到以下消息:

VerifyError: Error #1014: Class mx.core:BitmapAsset could not be found.

我可以看到这个类包含在 RSL.swc / RSL.swf 的类中。

我使用 fiddler 来观察正在发生的事情,我可以看到我的应用程序 swf 文件已加载,但没有尝试获取 RSL.swf。

将 Application.swf 文件设置为使用 RSL 后,我预计它会在初始化之前尝试加载 RSL.swf,但这不会发生。谁能建议为什么?

4

1 回答 1

1

来自http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_02.html

“如果基类是 Sprite 或 MovieClip,则不能在纯 ActionScript 项目中使用 RSL。RSL 要求应用程序的基类(例如 Application 或 SimpleApplication)了解 RSL 加载。”

由于我的基类是 Sprite,所以我遇到了这个错误。

就我而言,最好使用以下步骤将所有必需的类编译到我的应用程序 swf 文件中:

  1. 使用 compc 创建一个 SWC,其中包含我想要包含在我的应用程序 swf 文件中的文件
  2. 将 mxmlc 与指向要包含的 SWC 文件的包含库一起使用。使用链接报告生成链接文件报告 (xml)
  3. 使用指向链接文件报告 (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 时内存不足。

希望这有帮助!

于 2011-10-03T06:50:00.840 回答