AS3 将外部 SWF 加载到 Loader 时出现问题

发布于 2024-10-23 21:11:17 字数 214 浏览 4 评论 0原文

我有一个通过加载器组件加载外部 swf 的主应用程序。但一些单独运行良好的 swf 无法加载到主应用程序中。当我尝试从主应用程序的 fla 加载其中一个 swf 时,它给出了错误,表明它正在寻找某些类。从这个类的名称来看,它看起来像是加载的 swf 的一部分,但由于 swf 已经编译并且运行良好,为什么它在尝试由主应用程序加载时寻找这个类?

我没有找到任何涉及此类问题的内容。任何帮助将不胜感激。

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. 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. 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?

I didn't find anything that would refer to this kind of issue. Any help will be highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪痕残 2024-10-30 21:11:18

您似乎遇到了应用程序域冲突。如果每个 SWF 中的类名相互冲突(例如 swf1 有一个名为 Main 的类,swf2 也有一个名为 Main 的类),则可能会发生这种情况。

要解决此问题,请将 SWF 加载到新的应用程序域中:

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

如果不是这样,您很可能在影片的第一帧上有一些在 SWF 初始化时执行的代码(看看您是否在获取 Event 之前获取了 Event.INIT 。完全的)。

通过从框架中删除代码可以轻松解决此问题。

It seems like you got an application domain collision. This can happen if you got conflicting class names in each SWF (e.g swf1 has a class named Main, swf2 has a class named Main as well).

To fix that, load the SWFs into a new application domain:

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).

This can be easily fixed by removing the code from the frame.

优雅的叶子 2024-10-30 21:11:18

只是为了检查,我制作了仅包含 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)
}

此代码来自测试文件。
但即使这样,它仍然在寻找一些似乎是外部加载的 swf 之一的类。
错误如下:

TypeError: Error #1009: 无法访问空对象引用的属性或方法。
在 src::Dedo()
在 src::Main()

我的主应用程序中没有这样的类。所以它可能只是来自外部 swf 的类。

Just for checking I made fla file that contained only Loader component and code of loading:

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.
The error is such:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at src::Dedo()
at src::Main()

I have no such classes in my main app. So it could be only classes from external swf.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文