I’ve run into a peculiar problem while trying to make use of the Proxy class and override the getProperty() method. I’ve attached my example class code below:
package
{
import flash.utils.Proxy;
import flash.utils.flash_proxy;
public class Thing extends Proxy
{
// holder object
private var _holder:Object;
/**
* Constructor
*/
public function Thing()
{
_holder =
{
stuff: "thing"
};
}
/**
* Override getProperty
*/
override flash_proxy function getProperty(name:*):*
{
trace(name + " being accessed");
return _holder[name];
}
}
}
I’ve been trying to use this to make some properties read-only (as per an answer on a previous question of mine), however there’s some odd behaviour that I can’t seem to work out.
Using the above, I try and access the variable stuff like so:
var t:Thing = new Thing();
trace(t.stuff);
However this throws the following error:
1119: Access of possibly undefined property stuff through a reference
with static type Thing.
But if I do this:
trace(t["stuff"]);
It works fine. What am I doing wrong?
This is because your class isn’t dynamic, just add “dynamic” keyword and all will be good :