【问题标题】:Externally loaded SWF from application directory not loading twice从应用程序目录外部加载的 SWF 未加载两次
【发布时间】:2014-02-13 19:16:15
【问题描述】:

我有一个外部 SWF,我计划使用它来加载包含需要能够在不更改源文件的情况下进行更改的内容的影片剪辑。

我让它加载得很好,一切都运行良好,然后我卸载它,将值设置为 null 只是为了安全起见,应用程序仍然可以正常运行而没有错误,但是当我再次尝试加载它时,我的跟踪显示它正在加载 100%,但最终的 onComplete 函数似乎没有触发,除非我再次单击加载按钮,但随后它加载了 swf 的另一个副本。

有人遇到过类似的事情或知道发生了什么吗?

编辑:这是代码示例:

var swfFileName:String = "path/to/file.swf";
            var swfFilePath:File = File.applicationStorageDirectory.resolvePath(swfFileName); 
            var inFileStream:FileStream = new FileStream(); 
            inFileStream.open(swfFilePath, FileMode.READ); 
            var swfBytes:ByteArray = new ByteArray();
            inFileStream.readBytes(swfBytes);
            inFileStream.close(); 

            var loader:Loader = new Loader();
            var loaderContext:LoaderContext = new LoaderContext(false, ApplicationDomain.currentDomain);
            loaderContext.allowCodeImport = true;
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageLoading);
            loader.contentLoaderInfo.addEventListener(ErrorEvent.ERROR, loadError);
            loader.loadBytes(swfBytes, loaderContext);

这是删除代码:

function remover(event:Event = null):void {
                    loader.unloadAndStop();
                    loader = null;
                    swfFileName = null;
                    swfBytes = null;
                    loaderContext = null;
                    trace("removed");
                }

在 swfLoaded 函数中添加了一些内容并删除了 remover 函数,但我已经删除了这些内容以尝试缩小此示例中的原因。从我已经完成的跟踪中,Progress 事件中的百分比跟踪是在函数的第二次加载期间没有其他任何事情发生之前在 100 处触发的最后一件事。我第一次尝试运行它时,它运行良好,并以完美的功能显示所有内容。

【问题讨论】:

  • 分享您的代码。我们的心灵感应能力仍然很弱。 ;)
  • 你好吗unloading SWF?

标签: actionscript-3 flash loader


【解决方案1】:

我终于解决了这个问题。原来这一行:

new LoaderContext(false, ApplicationDomain.currentDomain);

由于某种我不完全理解的原因,导致它脱离上下文而被删除。我通过允许运行默认设置来修复它:

新的 LoaderContext();

唯一的缺点是我必须做更多的工作来加载和使用外部 swf 内的库对象,但现在它又可以工作了。

【讨论】:

    猜你喜欢
    • 2012-03-31
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 2011-06-11
    相关资源
    最近更新 更多