开发者

Actionscript - How to override getting pre-defined properties of classes?

I have a class which extends the Proxy class, and has a statically defined m开发者_如何学JAVAember 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?


If it's predefined why can't you use a getter/setter method and proxy access to private var that way?

private var _num:Number = 100;
//....
function get num () : Number { }
function set num (val : Number) : void { }


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 to num calls:

public dynamic class TestProxy extends Proxy
{
    private var _num:Number = 100;

    public function TestProxy()
    {
        super();
    }

    override flash_proxy function getProperty(name:*):*
    {
        if (name == "num")
        {
            return _num;
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜