从 AS3 中的框架脚本引用静态变量
有一些外部类,比如说 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您关闭编译选项“自动声明阶段实例”时会导致此问题,我通常这样做。您不能将阶段实例直接分配给静态变量。相反,您必须创建一个实例变量,然后将其分配给构造函数中的静态变量。
我想不出比这更复杂/更干净的解决方案了。
在某些项目中,无法选择打开自动声明。
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.