加载外部 SWF,无法将文档类转换为共享基类

发布于 2024-08-07 07:56:09 字数 565 浏览 11 评论 0原文

我有一个定义 Widget 基类的父 SWF 文件。

然后我将外部 SWF 加载到父级中。外部 SWF 的文档类派生自 Widget 基类 - 例如,我们将其称为 DerivedWidget。

问题是,当我加载外部 SWF 时,我无法将 Loader.content(在调试器中显示为具有 DerivedWidget 类型)转换为 Widget 类型。加载完成后,我使用“as”运算符将内容转换为父 SWF 中的小组件,但转换结果为“null”。

这种行为不是预期的,因为外部 SWF 已加载到父级应用程序域中,并且 Loader 的内容在调试器中显示为 DerivedWidget,我知道它派生自 Widget,但到基本 Widget 类的转换失败。

任何人都可以解释这种意外行为并提供解决方案吗?

[编辑:回顾一下早期的代码快照......这之前是有效的,但现在不行......并且加载和转换代码没有改变]

[Edit2:实际上,调试时似乎失败了在 Flash IDE 中。正常运行时,所有内容都会加载到正确的 ApplicationDomain (sameDomain=true) 中;这显然是一个巨大的错误]

I have a parent SWF file that defines a Widget base class.

I then load an external SWF into the parent. The external SWF's document class derives from the Widget base class -- let's call it DerivedWidget for example.

The problem is that when I load the external SWF, I cannot cast the Loader.content (shows in debugger as having the DerivedWidget type) to the Widget type. I use the "as" operator to cast the content as a Widget in the parent SWF once the load completes, but the cast results in "null".

This behavior is not expected, because the external SWF is loaded into the parent's application domain, and the Loader's content shows up in the debugger as DerivedWidget, which I know derives from Widget, but the cast to the base Widget class is failing.

Can anyone explain this unexpected behavior and offer a solution?

[Edit: looking back at an earlier code snapshot... this was working before, but now it isn't... and the loading and casting code hasn't changed]

[Edit2: actually, it seems to be failing when debugging in the Flash IDE. When run normally, everything loads into the correct ApplicationDomain (sameDomain=true); this is obviously a huge bug]

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

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

发布评论

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

评论(2

国际总奸 2024-08-14 07:56:09

DocumentClass 继承的方式存在一些错误。

http://bugs.adobe.com/jira/browse/FP-2999(需要登录 adobe 的错误跟踪器)

我的建议是将其从舞台上取下并通过库导出,它将从那里开始工作。事实上,我的经验法则是“永远不要使用文档类”。

There are some bugs in the way that DocumentClass does inheritance.

http://bugs.adobe.com/jira/browse/FP-2999 (need to log in to adobe's bug tracker)

My recommendation is to take it off the stage and export it through the library instead, it will work from there. In fact my rule of thumb is "never use document classes."

电影里的梦 2024-08-14 07:56:09

我也经历过类似的问题。解决方案有两个方面。

  1. 使用DerivedWidget(mc),而不是mc as DerivedWidget。有一些文章解决了这个问题,你需要找出来。

  2. 确保类 DerivedWidget 在两个编译环境中均可访问。如果您使用Module或涉及不同的Flash域,请更加小心。

I have experienced the similar problem. The solution are two fold.

  1. Use DerivedWidget(mc), instead of mc as DerivedWidget. There are some articles addressing this problem, you need to find it out.

  2. make sure the class DerivedWidget is accessible in both compilation environment. If you use Module or invovle different Flash domain, be more careful.

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