I am building an Adobe AIR app and I'm storing a Dictionary in my SharedObject. Something along the lines of what is mentioned here.
But why is the length of my dictionary always null. I end up having to manually keep track of the length which seems to work but doesn't fill me with confidence.
Also, can someone explain when exactly readExternal and writeExternal get called? I find that they are called multiple times (for what seems to me unnecessary). As it's a dictionary, adding the same value multiple times isn't proving a problem but again, wondering if I have setup something wrong here to trigger this.
This is what I have a
public class SharedObjectDictionary implements IExternalizable {
private var _dictionary:Dictionary;
private var _length:int;
public function addItem and removeItem
{
... just adds/removes to my _dictionary ...
... and keeps track of the length ...
}
public function readExternal(input:IDataInput):void
{
var count:int = input.readInt();
for (var i:Number = 0;i<count;i++)
{
var key:String = input.readObject();
var val:String = input.readObject();
addItem(key,val);
}
}
public function writeExternal(output:IDataOutput):void
{
output.writeInt(_length);
for (var key:Object in dictionary)
{
output.writeObject(key);
output.writeObject(dictionary[key]);
}
}
}
When I make the call to store this SharedObject as such
var so:SharedObject = SharedObject.getLocal("xxxx");
so.data["xxxxx"] = instance of the SharedObjectDictionary above;
so.flush();
so.close();
so = null;
I find that readExternal gets called once and writeExternal gets called 3 times.
Thanks!