Yes you can using Proxy function but with performance overhead:
import flash.utils.Dictionary;
import flash.utils.Proxy;
import flash.utils.flash_proxy;
public class MyDict extends Proxy {
private var _size:int = 0;
private var _dict:Dictionary = new Dictionary();
public function get size():int {
return _size;
}
flash_proxy override function getProperty(name:*):* {
return _dict[name];
}
flash_proxy override function setProperty(name:*, value:*):void {
if (!_dict.hasOwnProperty(name))
_size ++;
_dict[name] = value;
}
flash_proxy override function deleteProperty(name:*):Boolean {
if (_dict.hasOwnProperty(name)) {
_size --;
delete _dict[name];
return true;
}
return false;
}
}
var dict:MyDict = new MyDict();
dict[1] = 2;
dict["foo"] = "bar";
trace(dict.size, dict[1], dict["foo"]);
delete dict[1];
trace(dict.size, dict[1], dict["foo"]);