AS3 覆盖常量
我正在尝试执行以下操作:
public class character extends entity {
public const type:int = CHARACTER;
}
public class entity extends Sprite {
public const type:int = INVALID;
public const INVALID:int = -1;
public const CHARACTER:int = 1;
}
但编译器会抛出:
错误:与命名空间 public 中的继承定义 dieEngine:entity.type 存在冲突。公共常量类型:int = CHARACTER;
I am trying to do the following:
public class character extends entity {
public const type:int = CHARACTER;
}
public class entity extends Sprite {
public const type:int = INVALID;
public const INVALID:int = -1;
public const CHARACTER:int = 1;
}
But the compiler throws:
Error: A conflict exists with inherited definition dieEngine:entity.type in namespace public. public const type:int = CHARACTER;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,无论是否继承,常量都是常量,并且不应该被重写,可以将其想象为定义两倍于所需常量的完整类。
如果你确实想覆盖它,你应该设置
var
而不是const
使用:
而不是:
well, constants are constants no matter if they are inherited or not and should not be overriden, think of that like the a complete class which defines two times the required constant.
If you really want to override it, you should set that
var
instead ofconst
Use:
instead of:
这有帮助吗?您可以将 MovieClip 的属性设置为可以更改的常量:
然后在扩展类中,
如果您愿意,可以将常量设置为整数
Does this help at all? You can make the property of a MovieClip a constant that you can change:
Then in your extended class
You can make the constant an integer if you wish