Actionscript - 如何覆盖获取类的预定义属性?
我有一个扩展 Proxy 类的类,并且有一个名为 num
的静态定义成员变量:
public dynamic class TestProxy extends Proxy
{
private var num:Number = 100;
public function TestProxy()
{
super();
}
override flash_proxy function getProperty(name:*):*
{
trace("***** "+name);
}
}
我希望在尝试访问 num
时调用 getProperty()。它适用于任何尚不存在的字段,但不适用于预定义的字段。
有什么办法可以实现这一点吗?我可以以某种方式动态地摆脱 num
吗?或者其他什么?
I have a class which extends the Proxy class, and has a statically defined member variable called num
:
public dynamic class TestProxy extends Proxy
{
private var num:Number = 100;
public function TestProxy()
{
super();
}
override flash_proxy function getProperty(name:*):*
{
trace("***** "+name);
}
}
I want getProperty() to be called when I attempt access num
. It works for any field which does not already exist, but not for fields that are predefined.
Is there some way to make this happen? Can I somehow dynamically get rid of num
? Or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果它是预定义的,为什么不能使用 getter/setter 方法并以这种方式代理访问私有 var?
If it's predefined why can't you use a getter/setter method and proxy access to private var that way?
无法让 Proxy 访问类的私有预定义属性。如果您希望访问它,请将其公开,或者重命名该变量,然后响应
num
调用:There is no way to have
Proxy
access private pre-defined properties of a class. Either make it public if you want it accessed, or rename the variable and then respond tonum
calls: