【问题标题】:Load an SWF file and close it in the same window加载 SWF 文件并在同一窗口中将其关闭
【发布时间】:2018-08-15 14:20:57
【问题描述】:

我正在构建一个应用程序,用户单击一个按钮并在同一窗口中加载一个 SWF 文件,然后如果他完成,则使用关闭按钮将其关闭:

我希望用户能够点击橙色关闭按钮,并返回到第一帧(蓝色),

我试过这个:

orangeClosingButton.addEventListener(MouseEvent.CLICK, clickHandler);
 function clickHandler(event:MouseEvent):void {
  fscommand("quit");
 }

但这会关闭整个应用程序,我只想关闭灰色的 SWF 文件,然后返回蓝色的主应用程序,知道如何实现吗?

【问题讨论】:

  • 您需要在保存已加载 SWF 的 Loader 实例上调用 Loader.unloadAndStop() 方法:help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/…**
  • 我需要在主文件(蓝色的)还是加载的文件(灰色的)中调用它,因为“orangeClosingButton”在加载的文件中。
  • 好的,我会在几分钟后发布答案。

标签: actionscript-3 flash actionscript


【解决方案1】:

为了能够完全停止和卸载已加载的 SWF,您需要在 Loader 实例上调用 unloadAndStop() 方法,该实例保存已加载的内容。喜欢:

var outerSwf:Loader = new Loader;

// Load.
outerSwf.load(new URLRequest("outer.swf"));
addChild(outerSwf);

// ...
// Unload.
removeChild(outerSwf);
outerSwf.unloadAndStop();

然后,如果您想从加载的内容内部执行此操作。您可以将此方法订阅到按钮单击或调用它。

function unloadThisSWF(e:Event = null):void
{
    // Obtain the reference to the Loader instance.
    // In AS3 root will always point to the compiled SWF
    // root, not to the topmost root attached to the Stage.
    var aLoader:Loader = root.parent as Loader;

    // Run it only if this SWF was actually loaded.
    if (aLoader)
    {
        // Detach it from display list if attached.
        if (aLoader.parent)
        {
            aLoader.parent.removeChild(aLoader);
        }

        // Invoke the unload.
        aLoader.unloadAndStop();
    }
}

【讨论】:

  • 谢谢,帮了大忙。
【解决方案2】:

取决于您如何加载内部 SWF。假设这是 ActionScript2 并且这段代码在加载的电影(灰色)中,这样的事情可能会起作用:

orangeClosingButton.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
  // remove the event listener so the loaded movie can be garbage collected
  orangeClosingButton.removeEventListener(MouseEvent.CLICK, clickHandler);
  unloadMovie(this);
}

不确定是否可以从内部 swf 中卸载电影,也许这个 unloadMovie() 必须在主 SWF 中以及您加载电影的位置。

如果这是 AS3,您应该使用 removeChild(yourMovieClip) 而不是 unloadMovie

【讨论】:

  • unloadMovie 函数是 AS1/2 函数,而不是 AS3。
  • 我试过了,但我得到了这个错误:“提供的 DisplayObject 必须是调用者的孩子”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-27
  • 2021-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多