为什么没有加载我的标准 RSL?



我创建了一个模块化应用程序,其中父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中提取了RSL.swf。把它放到我的web服务器上,与应用程序的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,然而这并没有发生。有人能告诉我为什么吗?

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

"如果基类是Sprite或MovieClip,则不能在仅使用actionscript的项目中使用RSLs。RSL要求应用程序的基类(如application或SimpleApplication)理解RSL加载。"

因为我的基类是Sprite,所以出现了这个错误。

在我的例子中,最好使用以下步骤将所有必需的类编译到Application swf文件中:

  1. 使用compc创建一个SWC文件,我想包括在我的应用程序swf文件
  2. 使用mxmlc和include-libraries指向要包含的SWC文件。使用link-report生成一个链接文件报告(xml)
  3. 用load-extern指向所链接的文件报告(xml)编译每个附加的子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在编译许多swfs时耗尽内存。

希望这是有帮助的!

最新更新