Skip to content

Instantly share code, notes, and snippets.

@saumya
Created October 4, 2010 19:46
Show Gist options
  • Save saumya/610295 to your computer and use it in GitHub Desktop.
Save saumya/610295 to your computer and use it in GitHub Desktop.
package com.saumya.study
{
import flash.utils.Dictionary;
import flash.utils.Proxy;
import flash.utils.flash_proxy;
/**
* Learning the proxy object
* @author saumya
* @version 0.0.1
*/
public dynamic class MyProxyObject extends Proxy
{
private var dict:Dictionary = new Dictionary();
public function MyProxyObject()
{
//trace('MyProxyObject : ', this);
}
override flash_proxy function callProperty(name:*, ...rest):*
{
trace('MyProxyObject : callProperty : name=', name);
var s:String = String(name);
var resultNow:*=null;
switch(s)
{
case 'age':
resultNow = this.dict[name] + 2;//always add 2 more years
break;
case 'drink':
if (this.dict[name]== undefined )
{
this.dict[name] = rest;
}else {
resultNow = 'I am drinking ' + this.dict[name];
}
break;
default:
trace('MyProxyObject : callProperty : default : This is not handled yet! s=',s);
break;
}
return resultNow;
}
override flash_proxy function getProperty(name:*):*
{
trace('MyProxyObject : getProperty : name=', name);
var resultNow:*=null;
resultNow = this.dict[name];
return resultNow;
}
override flash_proxy function setProperty(name:*,value:*):void
{
trace('MyProxyObject : setProperty : name=', name, ' : value=', value);
this.dict[name] = value;
if (String(name)==='age')
{
if (value < 0)
{
this.dict[name] = 0;
}
}
}
override flash_proxy function hasProperty(name:*):Boolean
{
trace('MyProxyObject : hasProperty : ', name);
return this.hasOwnProperty(String(name));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment