【问题标题】:How do i run a swf file in another swf file?如何在另一个 swf 文件中运行一个 swf 文件?
【发布时间】:2021-12-25 22:08:28
【问题描述】:

我的游戏有一个带有 GUI 的客户端,我尝试在您按下按钮打开另一个 swf 文件时添加。所以基本上在按下按钮后被重定向到另一个 swf 文件。 代码如下:

override public function set pressed(param1:Boolean) : void
      {
         super.pressed = param1;
         bitmap.y = !!param1 ? Number(1) : Number(0);
      }

我已经尝试过这样做:

override public function set pressed(param1:Boolean) : void
      {
         super.pressed = param1;
         bitmap.y = !!param1 ? Number(1) : Number(0);
         mainLoader = new Loader();
         url = new URLRequest("battle/battle.swf");
         mainLoader.load(url);
         addChild(mainLoader);      
}

但它只是把客户端中的一切都搞砸了,甚至不起作用......

【问题讨论】:

  • 请详细解释“搞砸一切”。正如您提供的那样,第二个 sn-p 应该开始加载一些外部 SWF,同时将其 添加 到现有的显示列表层次结构中。如果“重定向”的意思是要完全删除当前内容以运行外部 SWF,则应该以稍微不同的方式进行。
  • 我只是想让它开始加载外部 swf 并显示它
  • 你做到了。它加载外部 SWF 并显示它。这里没有问题,除非你用“预期与实际”的结果来解释。
  • 所以我希望当按下的功能被激活以显示另一个 swf 文件时,它会以另一种形状显示按钮,就像 4 像素一样非常小,当我尝试单击它时,它什么都不做

标签: actionscript-3 flash


【解决方案1】:

好的,我仍然觉得您的“预期行为”解释非常混乱,但我假设您希望您的应用程序显示另一个 SWF,就像浏览器中的下一页一样。

function nextSWF(url:String):void
{
    // Keep the stage reference because it will be lost
    // once everything is detached from the stage,
    // and that is exactly what's about to happen.
    var aStage:Stage = stage;
    var aLoader:Loader = new Loader;
    
    // Remove the current application visuals.
    dismantle(aStage);
    
    // Load the new content.
    aStage.addchild(aLoader);
    aLoader.load(new URLRequest(url));
}

// This method recursively destroys the whole display list
// branch, starting from the given display list node.
function dismantle(target:DisplayObjectContainer):void
{
    if (!target) return;
    
    while (target.numChildren)
    {
        // Get a reference to the topmost display child.
        var aChild:DisplayObject = target.getChildAt(target.numChildren - 1);
        
        // Dismantle it as well if it contains things, 
        // then remove it from the display list.
        dismantle(aChild as DisplayObjectContainer);
        target.removeChild(aChild);
    }
}

然后,您在脚本中使用它,如下所示:

override public function set pressed(param1:Boolean) : void
{
    // The remnants of your script, whatever it is.
    super.pressed = param1;
    bitmap.y = !!param1 ? Number(1) : Number(0);
    
    // Remove the current content and load the next one.
    nextSWF("battle/battle.swf");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多