加载多个本地SWF时AS3错误1014

时间:2013-02-13 21:33:17

标签: actionscript-3

我有两个SWF,称它们为A和B.它们永远不会部署到网站上,而是用于工具。 B依赖于A - B中的一些类扩展了A中的类。

我现在正在创建第三个SWF,称之为X.X正在尝试使用flash.display.Loaderflash.net.URLRequest加载A和B. A和B路径被推入一个数组,然后在loadLibrary函数中调用,如下所示:

public class LibraryLoader
{
    private static const CLASS_NAME:String = "LibraryLoader";
    private var _libraries:DisplayObjectContainer;

    ...

    public function loadLibrary(callback:Function, libName:String):void
    {
        trace("loadLibrary('" + libName + "')");

        var loader:Loader = new Loader();
        loader.name = libName;

        var listener:Function = function(e:Event):void
        {
            trace("finished loading '" + libName + "', event: " + e);
            loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, listener);
            _libraries.addChild(loader);
            callback();
        }

        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, listener);
        loader.load(new URLRequest(libName));
    }

问题是,当我加载B时,它会抛出错误。这是输出:

loadLibrary('C:\path\to\A.swf')
finished loading 'C:\path\to\A.swf', event: [Event type="complete" bubbles=false cancelable=false eventPhase=2]
loadLibrary('C:\path\to\B.swf')
[Fault] exception, information=VerifyError: Error #1014: Class a.class.in::A could not be found.

这个类在A里面,B依赖它。

我用Google搜索并找到有关安全权限和沙箱的信息 - 也许我需要在这些SWF之间建立一些信任。那很好,但我似乎无法弄清楚如何正确地做到这一点。

首先,我尝试设置一个像这样的LoaderContext(当加载两个SWF时):

var context:LoaderContext = new LoaderContext();
context.applicationDomain=ApplicationDomain.currentDomain;
loader.load(new URLRequest(libName), context);

没有骰子,那里;同样的错误。此外,尝试设置context.securityDomain会抛出:

[Fault] exception, information=SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property. file:///C|/path/to/X.swf was attempting to load file:///C:/path/to/A.swf.

如果它有所不同,则使用Flex SDK(3.6)中的compc.exe编译A和B.我为每个生成SWF和SWC - 运行时使用SWF,使用compc生成SWC进行编译。这是compc的命令行:

compc.exe  -output C:\temp\dir -source-path   -include-sources C:\path\to\A\source -directory=true -incremental=true -debug=true  -use-network=false 
compc.exe  -output C:\path\to\A.swc -source-path   -include-sources C:\path\to\A\source -incremental=true -debug=true  -use-network=false 
compc.exe  -output C:\temp\dir -source-path   -include-sources C:\path\to\B\source -directory=true -incremental=true -debug=true  -external-library-path+=C:\path\to\A.swc -use-network=false 

在第一次和第三次编译之后,将“library.swf”文件放入列出的临时目录中。我拿出那些SWF并将它们重命名为A.swf和B.swf,将它们放在我想要的地方。

我的X项目是用Flash Player 10.1的FlashDevelop 4.0.1构建的。

我知道a.class.in::A包含在SWF A中。我在Scaleform运行时加载这些SWF没有任何问题,因此我确信FlashPlayer的工作方式存在某种问题。

当我从X加载A和B时,如何让B看到A中的类?

1 个答案:

答案 0 :(得分:1)

有三条评论:

  1. 你是对的,当你指定applicationDomainApplicationDomain.currentDomain;时没有这个加载器加载swf来分隔具有共同父级的子域,所以他们看不到彼此的类。
  2. 对于通用的应用程序域,A中的类必须可以从B访问,所以我只看到错误的一种可能性:A真的没有类some.class.in.A。尝试检查这个类是否包含在A中(例如通过Sothink SWF Decompiler)或者只是检查这个类是否在A中的代码中显式使用。如果没有使用它不包括在内,你可以强制包括这个类通过在代码中添加它:只需将some.class.in.A添加到A中没有new语句的位置。
  3. context.securityDomain用于其他目的,仅在由http加载的swf文件时使用,并且不在本地应用。
相关问题