简体   繁体   English

如何在另一个 swf 文件中运行一个 swf 文件?

[英]How do i run a swf file in another swf file?

I got a client with a GUI for my game and i tried adding when you press a button to open another swf file.我的游戏有一个带有 GUI 的客户端,当您按下按钮打开另一个 swf 文件时,我尝试添加。 So basically after when the button is being pressed to be redirected to the other swf file.所以基本上在按下按钮后被重定向到另一个 swf 文件。 Here is the code:这是代码:

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

And i have tried doing this:我试过这样做:

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);      
}

But it just messes up everything in the client and it doesn't even work...但它只会弄乱客户端中的所有内容,甚至无法正常工作......

Ok, I still find your " expected behavior " explanations to be exceedingly confusing, but I assume you want your application to show another SWF just like next page in browser.好的,我仍然发现您的“预期行为”解释非常令人困惑,但我假设您希望您的应用程序显示另一个 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);
    }
}

Then, you use it in your script as following:然后,您在脚本中使用它,如下所示:

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");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM