How to extend ObjectProxy class
I trying to extends ObjectProxy class, the reason is because I want to have a Singleton of the ObjectProxy class, so I made something like
package utils
{
import mx.utils.开发者_StackOverflow社区ObjectProxy;
public class UniformObjectProxy extends ObjectProxy
{
private static var _instance:UniformObjectProxy;
public function UniformObjectProxy(secure:PrivateClass, item:Object=null, uid:String=null, proxyDepth:int=-1)
{
super(item, uid, proxyDepth);
}
public static function getInstance(item:Object=null):UniformObjectProxy{
if(UniformObjectProxy._instance == null){
var security:PrivateClass = new PrivateClass();
UniformObjectProxy._instance = new UniformObjectProxy(security, item);
}
return UniformObjectProxy._instance;
}
}
}
class PrivateClass{
public function PrivateClass(){
}
}
when I create my object uniform which is a simple object, I pass it to my UniformObjectProxy.getInstance() static method to get the instance of my objectProxy, ok so far so good
my problem is when I try to bind a property of my objectProxy instance like
_opc = UniformObjectProxy.getInstance(_uniform);
cw:ChangeWatcher = BindingUtils.bindSetter(dispatchColorChange, _opc, data.id);
the dispatchColorChange handler function is called only once an never again, I had check ChangeWatcher.isWatching() and return false meaning my objectProxy is not binding properly, if I create an objectProxy like
_opc = new ObjectProxy(_uniform);
cw:ChangeWatcher = BindingUtils.bindSetter(dispatchColorChange, _opc, data.id);
the binds works just fine, so my thinking is the problem is when I extends the objectProxy class, how is the proper way to do this, please help me!, thanks for any clue!!
There seems to be problems extending ObjectProxy (personally I encountered namespace issues while trying overriding the setProperty method and have the feeling this class is just not meant to be used the same way as the Proxy class).
Not a direct answer to your question but I guess you shouldn't have to stick to the singleton pattern just for the sake of it. To get the same access/result described above I would suggest doing something like this :
package utils
{
import mx.utils.ObjectProxy;
public class UniformObjectProxy
{
private static var _proxy:ObjectProxy;
public function UniformObjectProxy()
{
throw("do not instantiate me!")
}
public static function getProxy(item:Object=null):ObjectProxy{
if(_proxy == null){
_proxy = new ObjectProxy(item);
}
return _proxy;
}
}
}
and then :
var _opc:ObjectProxy = UniformObjectProxy.getProxy(_uniform);
精彩评论