0

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?

Fragsworth
  • 33,919
  • 27
  • 84
  • 97

2 Answers2

0

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 { }
John Giotta
  • 16,432
  • 7
  • 52
  • 82
  • This is exactly what I'm trying to avoid; I am trying to define model objects whose properties are looked up lazily + remotely upon getting them, as the data does not exist in the class upon instantiation. It is not just one object, it is potentially dozens; writing these getters/setters to do **exactly the same thing** for each property would be an awful hassle and seems really unclean. – Fragsworth Jan 13 '11 at 20:35
0

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;
        }
    }
}
Richard Szalay
  • 83,269
  • 19
  • 178
  • 237