简体   繁体   English

AS3将外部SWF加载到Loader中的问题

[英]AS3 Problem in loading external SWF into Loader

I have main application that loads external swf's through the Loader Component. 我有通过加载程序组件加载外部瑞士法郎的主要应用程序。 But some swf's that are working well on their own don't load into the main app. 但是一些运行良好的SWF文件不会加载到主应用程序中。 When I tried to load one of that swf's from fla of main app it gave error that it's looking for some classes. 当我尝试从主应用程序的fla加载该SWF文件之一时,出现错误,它正在寻找某些类。 By the name of this classes it looks like it were parts of loaded swf but as swf that is already compiled and working well why is it looking for this class when it's trying to be loaded by the main app? 通过此类的名称,它看起来像是已加载的swf的一部分,但由于swf已被编译并且运行良好,为什么在尝试由主应用程序加载时会寻找此类?

I didn't find anything that would refer to this kind of issue. 我没有发现任何涉及此类问题的信息。 Any help will be highly appreciated. 任何帮助将不胜感激。

It seems like you got an application domain collision. 似乎您遇到了应用程序域冲突。 This can happen if you got conflicting class names in each SWF (eg swf1 has a class named Main, swf2 has a class named Main as well). 如果每个SWF中的类名冲突(例如swf1的类名为Main,swf2的类也称为Main),则可能会发生这种情况。

To fix that, load the SWFs into a new application domain: 要解决此问题,请将SWF加载到新的应用程序域中:

loader.load(new URLRequest("g.swf"), new LoaderContext(false, new ApplicationDomain(ApplicationDomain.currentDomain)));

If it's not that, you most likely have some code on the first frame of the movie that executes on initialisation of the SWF (See if you get Event.INIT before you get Event.COMPLETE). 如果不是那样,则很可能在影片的第一帧上有一些代码在SWF初始化时执行(请在获取Event.COMPLETE之前先查看是否获取Event.INIT)。

This can be easily fixed by removing the code from the frame. 通过从框架中删除代码,可以轻松解决此问题。

Just for checking I made fla file that contained only Loader component and code of loading: 为了检查,我制作了仅包含Loader组件和加载代码的fla文件:

var loader:Loader = new Loader();
addChild(loader);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingFunc);
loader.load(new URLRequest("g.swf"));

function loadingFunc(event:Event):void{
    var li:LoaderInfo = event.target as LoaderInfo;
    var mc:MovieClip = MovieClip(li.content)
}

This code is from the testing file. 此代码来自测试文件。 But even this way it still looking for some class that seems to be one of external loaded swf. 但是即使这样,它仍然会寻找某种似乎是外部加载的swf之一的类。 The error is such: 错误是这样的:

TypeError: Error #1009: Cannot access a property or method of a null object reference. TypeError:错误#1009:无法访问空对象引用的属性或方法。 at src::Dedo() at src::Main() 在src :: Dedo()在src :: Main()

I have no such classes in my main app. 我的主应用程序中没有此类。 So it could be only classes from external swf. 因此,它可能只是来自外部swf的类。

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

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