加载外部 swf 时 Flash 崩溃(最终陷入重启循环)

发布于 2024-09-07 06:19:40 字数 920 浏览 7 评论 0原文

我正在与 FlashDevelop 合作,有两个主要项目,都是纯 AS3 项目。

当尝试从主项目加载第二个项目时,我收到各种错误。

主项目的 Main 类扩展了 Sprite,“待导入”项目中的 Main 类扩展了 MovieClip。查看 FD 中调试窗口中 swf 的加载情况,一切似乎都很好:

[SWF] 'pathToSwf'\secondProject.swf - 410 626 bytes after decompression.

如果我尝试将加载的 swf 分配给新创建的 MovieClip,我会遇到强制失败:

swfContent = loader.content; // =>
Type Coercion failed: cannot convert Main@46c0201 to flash.display.MovieClip.

因此,像这样对加载的内容进行类型转换:

swfContent = loader.content as MovieClip;

可以消除该错误,但是然后当我尝试调用 addChild 时,我陷入了下一个坑:

Error #2007: Parameter child must be non-null.

试图解决这个问题,我尝试将加载器直接添加到我想要显示外部 swf 的容器中。这是真正有趣的问题开始的时候:

targetContainer.addChild(loader);

我的主应用程序现在挂起,在永无休止的循环中重新启动。我不知道为什么......

所以我的问题确实是。我的外部 swf 如何加载但又为空。 当我单独运行外部 swf 时,它工作得很好......

Im working with FlashDevelop and have two main projects, all pure AS3 projects.

When trying to load my second project from my main project I get all kinds of errors.

The Main class of the main project extends Sprite and the Main class in the "to-be-imported" project extends MovieClip. Looking at the loading of the swf in the debug window in FD it all seems fine:

[SWF] 'pathToSwf'\secondProject.swf - 410 626 bytes after decompression.

If i try to assign the loaded swf to a newly created MovieClip I get a coercion failiure:

swfContent = loader.content; // =>
Type Coercion failed: cannot convert Main@46c0201 to flash.display.MovieClip.

So, typecasting the loaded content like so:

swfContent = loader.content as MovieClip;

removes that error but then I fall into the next pit as I try to call addChild:

Error #2007: Parameter child must be non-null.

Trying to get around the issue I tried to add the loader directly into the container where I want to show the external swf. This is when the real interesting problems begin:

targetContainer.addChild(loader);

My main application now hang, restarting in a never ending loop. I have no idea why..

So my issue is really. How can my external swf be loaded but then again be null.
It works perfectly fine when I run the external swf by itself...

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

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

发布评论

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

评论(4

以酷 2024-09-14 06:19:40

使用 getQualifiedClassName 和 < a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getQualifiedSuperclassName%28%29" rel="nofollow noreferrer">getQualifiedSuperclassName 函数(甚至describeType(如果必须) ) 在 loader.content 上获取其确切的类型信息。

loader.content as MovieClip 返回 null,因为 loader.content 不是 MovieClip - 使用 as 进行投射 关键字在失败时默默返回 null。加载的内容是否有可能是 AS2 影片剪辑而不是 AS3 影片剪辑?在这种情况下,getQualifiedClassName 将返回“AVM1Movie”

Use getQualifiedClassName and getQualifiedSuperclassName functions (and even describeType if you must) on loader.content to get its exact type information.

loader.content as MovieClip returns null because loader.content is not a MovieClip - casting with as keyword silently returns null when it fails. Is there any chance that the loaded content is an AS2 movie clip instead of AS3 movie clip? In that case getQualifiedClassName will return "AVM1Movie".

绝不放开 2024-09-14 06:19:40

后面的问题很奇怪,但首先尝试将 swfContent 的类型更改为 Sprite。主类并不总是扩展MovieClip,从错误消息来看,在这种情况下确实没有扩展。

The latter issues is weird, but first try changing the type of swfContent to Sprite. A main class does not always extend MovieClip, and judging from the error message it indeed doesn't in this case.

紫﹏色ふ单纯 2024-09-14 06:19:40

如果您的 swfContent 无法转换为 MovieClip,则其将为 null。这就是当类型强制失败时 as 运算符应该如何工作。

像这样修改您的赋值操作:

var swfContent :MovieClip = MovieClip(loader.content);

您可能希望将赋值包含在 try...catch 块中,因为失败时会抛出错误,而不是 swfContent > 被设置为 null,与 as 一样。

Your swfContent will be null, if it cannot be casted to MovieClip. That is how the as operator is supposed to work when type coercion fails.

Modify your assignment operation like this:

var swfContent :MovieClip = MovieClip(loader.content);

You might want to encompass the assignment in a try...catch block, as an error will be thrown in case of failure, instead of swfContent being set null, as with as.

べ繥欢鉨o。 2024-09-14 06:19:40

所以问题是我加载的 swf 的主类与我加载的 swf 具有相同的名称。这导致当 flash 尝试执行加载的 swf 时,它实际上调用父 MAIN 类,从而导致循环行为。

为了避免这种情况,DHuntrods 建议更改应用程序域来解决该问题。

loader = new Loader();
var AD:ApplicationDomain = new ApplicationDomain( null );
var context:LoaderContext = new LoaderContext( false, AD );
loader.load(new URLRequest(path), context);

So the problem was that the main class of my loaded swf had the same name as the swf I was loading from. This led to that when flash tries to execute the loaded swf it actually calls the parent MAIN class which results in the looping behaviour.

To avoid this DHuntrods suggested to change the application domain which solved the issue.

loader = new Loader();
var AD:ApplicationDomain = new ApplicationDomain( null );
var context:LoaderContext = new LoaderContext( false, AD );
loader.load(new URLRequest(path), context);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文