我有两个SWF,称它们为A和B.它们将永远不会部署到网站,并且正在用于工具。 B依赖于A - B中的某些类扩展A中的类。加载多个本地SWF时AS3错误1014
我正在创建第3个SWF,称其为X.X正试图使用flash.display.Loader
和flash.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依赖它。
我搜索并找到有关安全权限和沙箱的信息 - 也许我需要在这些SWF之间建立一些信任关系。这很好,但我似乎无法弄清楚如何正确地做到这一点。
首先,我试图建立一个LoaderContext像这样(装在两个主权财富基金):
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.
在情况下,它有差别,A和B正在使用compc.exe
从Flex SDK(3.6)编译。我为每个SWF生成一个SWF和一个SWC,用于运行时SWF和用于编译的SWC - 使用compc。下面是通过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中。我在没有问题的情况下将这些SWF加载到Scaleform运行时中,因此我确信在FlashPlayer的工作方式上存在某种问题。
当我从X载入A和B时,如何让B看到A中的类?
在加载loaderB之前,您是否确保loaderA完全加载? – Marcela 2013-02-13 21:48:23
@Marcela很确定,是的。更新了代码片段,以显示我如何等待完整事件。 – 2013-02-14 14:08:56