闪存加载第一个外部SWF加载 [英] Flash loading first external swf loaded

查看:99
本文介绍了闪存加载第一个外部SWF加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在申请从我自愿参加的游戏中测试艺术作品.现在,我发布的示例仅会碰到盔甲,但是整个程序的加载过程是相同的.我已经准备好要保存加载的文件的动画片段,但它会通过该类将其添加到容器中.它起作用了,但是我的问题是,如果您使用具有相同类的另一个文件,则它将默认为加载的第一个文件.即使我使用loaderr.unloadAndStop()并从舞台上删除所有内容,它也将始终加载与我要加载的类相对应的第一个文件.由于装甲是按类加载的,因此无需更改每次导出的类就可以轻松测试装甲文件的多个更改.这是正在使用的代码的示例,我很好奇是否有任何方法可以改善此问题. `

I am making an application to test art from a game I volunteered for. Right now the example I am posting will only touch the armors but the loading process is the same throughout the program. I have a movieclip ready to hold the loaded file but it adds it to the container via the class. It works how it should however my issue is that if you use another file with the same classes then it will default to the first file loaded. Even i use loaderr.unloadAndStop() and remove everything from the stage, it will always load the first file that corresponds to the class I am loading by. Since the armor pieces are loaded by class it makes it a hassle to test multiple changes to an armor file without changing the classes on each export. Here is an example of the code that is being used and I am curious if there is any way that I can improve this. `

public class Test extends MovieClip
{
    public var mcChar:Display;
    public var btnTest:SimpleButton;
    public var btnTest2:SimpleButton;
    public var ldr:Loader = new Loader();
    public var strSkinLinkage:String;
    public var strGender:String;

    public function Test()
    {
        btnTest.addEventListener(MouseEvent.CLICK, TestP);
        btnTest2.addEventListener(MouseEvent.CLICK, TestP2);
    }

    public function TestP(e:MouseEvent)
    {
        mcChar = new Display();
        stage.addChild(mcChar);
        mcChar.x = 789.6;
        mcChar.y = 604.75;
        mcChar.width = 667.15;
        mcChar.height = 478.55;
        strSkinLinkage = "CNC";
        strGender = "M"
        this.ldr.load(new URLRequest("CNC.SWF"), new LoaderContext(false, ApplicationDomain.currentDomain));
        this.ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onLoadSkinComplete);
    }
    public function TestP2(e:MouseEvent)
    {
        mcChar = new Display();
        stage.addChild(mcChar);
        mcChar.x = 789.6;
        mcChar.y = 604.75;
        mcChar.width = 667.15;
        mcChar.height = 478.55;
        strSkinLinkage = "CNC";
        strGender = "M"
        this.ldr.load(new URLRequest("CNC2.SWF"), new LoaderContext(false, ApplicationDomain.currentDomain));
        this.ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, this.onLoadSkinComplete);
    }

    public function onLoadSkinComplete(e:Event):*
    {
        var AssetClass:Class;
        try
        {
            AssetClass = (getDefinitionByName(((strSkinLinkage + strGender) + "Head")) as Class);
            mcChar.head.addChildAt(new (AssetClass)(), 0);
        }
        catch(err:Error)
        {
            AssetClass = (getDefinitionByName(("mcHead" + strGender)) as Class);
            mcChar.head.addChildAt(new (AssetClass)(), 0);
        };
        AssetClass = (getDefinitionByName(((strSkinLinkage + strGender) + "Chest")) as Class);
        chest.addChild(ldr.content (AssetClass)());
        mcChar.chest.addChild(new (chest)());
        this.ldr.contentLoaderInfo.removeEventListener(Event.COMPLETE, this.onLoadSkinComplete);
    }
}

` 我认为它在本网站上的格式不正确,但这是核心代码.我有单独的删除功能,所有导入都在那里.就像我说的那样,我似乎无法正确格式化.这是我的测试场景,而不是我可以选择文件的完整动态测试器.感谢您对如何使用最新文件的任何帮助.同样对于某些背景,我更像是as3中的自学新手.

` I don't think its well formatted on this site but this is the core code. I have separate removal functions and my imports are all there. Like I said I cant seem to get it to format correctly. This is my test scenario and isn't my full dynamic tester where I can choose the file. Any help in figuring out how to use the most recent file is appreciated. Also for some background I am more of a self taught novice in as3.

推荐答案

在AS3中加载和卸载资产时,有几件事需要学习.

When it gets to loading and unloading assets in AS3, there are several things to learn.

ApplicationDomain 是一个类定义的容器. getDefinitionByName(... )方法与调用在当前 ApplicationDomain 上(或者也许在主 ApplicationDomain 上的ApplicationDomain.getDefinition(...)),我从没有尝试过它在加载的内容中).附带的结果是,您不能在同一个 ApplicationDomain 中包含两个具有相同名称的类(或者您可以,但是其中一个是无法访问的,谁知道).

ApplicationDomain is a container for class definitions. The getDefinitionByName(...) method is basically the same as calling the ApplicationDomain.getDefinition(...) on the current ApplicationDomain (or maybe on the main ApplicationDomain, I never tried to do it in the loaded content). As the side result, you cannot have two classes with the same names inside the same ApplicationDomain (or rather you can, but one of them is inaccessible, who knows).

当您加载属于相同域"类别(相同的 www 域,或相同/嵌套的本地文件夹)的另一个SWF时,AS3会自动将已加载的SWF中的所有定义混合到主域中 ApplicationDomain .如果您希望对加载/卸载内容进行某些高级控制,或者/并且有一些皮肤"库具有相似的类集,则需要将加载的文件放入单独的 ApplicationDomain 或它们的定义会发生冲突,结果将无法预测(但显然还不能令人满意).

When you load another SWF which falls into the "same domain" category (same www domain, or same/nested local folder), AS3 automatically mixes all the definitions from the loaded SWF into the main ApplicationDomain. If you are willing to have some advanced control over loading/unloading stuff, or/and there are "skin" libraries that have similar sets of classes, you need to put the loaded files into separate ApplicationDomains or their definitions will collide and the result will be unpredictable (yet obviously not satisfactory).

加载器. load(...)方法有第二个参数,您可以这样做:

The Loader.load(...) method has a second argument that allows you to do so:

// If there are no mandatory constructor arguments,
// you are free to omit the () brackets. I like doing so.
var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest("mylibrary.swf");

// Documentation states that passing no argument here is
// the same as passing ApplicationDomain.currentDomain.
var childDomain:ApplicationDomain = new ApplicationDomain;
var aContext:LoaderContext = new LoaderContext(false, childDomain);

aLoader.load(aRequest, aContext);

因此,在加载外部SWF库时,您可以按以下方式获取其类/定义:

Thus, when external SWF library is loaded, you can obtain its classes/definitions as following:

var aClass:Class;

// If you get things from the loaded SWF's Library
// then it is Sprite or MovieClip for the most cases.
var anAsset:Sprite;

aClass = aLoader.contentLoaderInfo.applicationDomain.getDefinition("MyAssetClass") as Class;
anAsset = new aClass;

当您不再需要某些已加载的库时,请调用

When you do not longer need some of the loaded libraries, you call the Loader.unloadAndStop(...) method on the relevant Loader instance. Combined with the loading SWF into separate ApplicationDomain you can be sure that all of the loaded content (graphics, classes, sounds) is unloaded, destroyed and removed (that one I actually checked):

// Passing "true" also forces the Garbage Collector
// to actually do its job for a change.
aLoader.unloadAndStop(true);

这篇关于闪存加载第一个外部SWF加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆