从 AS3 中的框架脚本引用静态变量

发布于 2024-08-09 06:31:32 字数 316 浏览 2 评论 0原文

有一些外部类,比如说 MyClass.as

MyClass.as 有一个名为 foo 的静态变量

,所以,通常在其他 AS 文件中我可以用

MyClass.foo = bar;

来调用它然而,这在时间线脚本中似乎有所不同。

每次尝试此操作时,我都会得到带有静态类型错误 1119 的引用

:通过静态类型 flash.display:DisplayObjectContainer 的引用访问可能未定义的属性 foo。

我尝试过导入 MyClass 等...似乎没有任何效果。

有什么建议吗?

Got some external classes, say MyClass.as

MyClass.as has a static variable called foo

So, ordinarily in other AS files I can call this with

MyClass.foo = bar;

However, this seems to be different in timeline scripts.

Every time I try this I get the reference with a static type error

1119: Access of possibly undefined property foo through a reference with static type flash.display:DisplayObjectContainer.

I've tried doing an import MyClass, etc... nothing seems to be firing.

Any tips?

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

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

发布评论

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

评论(1

临风闻羌笛 2024-08-16 06:31:32

当您关闭编译选项“自动声明阶段实例”时会导致此问题,我通常这样做。您不能将阶段实例直接分配给静态变量。相反,您必须创建一个实例变量,然后将其分配给构造函数中的静态变量。

我想不出比这更复杂/更干净的解决方案了。

在某些项目中,无法选择打开自动声明。

This problem is caused when you have the compile option "Automatically Declare Stage Instances" turned off, which I commonly do. You cannot assign a stage instance to a static variable directly. Instead you must create an instance variable, and then assign it to a static variable in the constructor.

I cannot think of a more elaborate/clean solution than this.

There are some projects where turning on Auto-declare is not an option.

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