Correctly serialize flash.utils.Dictionary to SharedObject

I have a convenience class in my Flex project called HashMap, which is essentially a wrapper around flash.utils.Dictionary with a bunch of convenience methods and an added (synchronized) ArrayCollection, so that I can pass the HashMap to the bindable that the ArrayCollection wants. Everything works perfectly.

What doesn’t work fine, I’m now figuring out, puts this HashMap in a local SharedObject.

Registering a class makes it save and return as the correct type, and the ArrayCollection member returns just fine, but the Dictionary does not save its data.

Here is a snippet:

[RemoteClass(alias="com.tamedtornado.collections.HashMap")]
public class HashMap extends Proxy
{
    public var hash:Dictionary = new Dictionary();

    // Keeps an array collection as well so we can give this to a data bound control

    [Bindable]
    public var collection:ArrayCollection = new ArrayCollection();

, - . ? ArrayCollection , , SO , ( ).

+3
1

, " ", , , IExternalizable .

    public function readExternal(input:IDataInput):void
    {
        var hashCount:int = input.readInt();

        for (var i:int = 0;i<hashCount;i++)
        {
            var prop:Object = input.readObject();
            var val:Object = input.readObject();

            putEntry(prop,val);
        }
    }

    public function writeExternal(output:IDataOutput):void
    {
        output.writeInt(collection.length);

        for (var prop:Object in hash)
        {
            output.writeObject(prop);

            output.writeObject(hash[prop]);
        }
    }

. (, String), [registerClassClass]/registerClassAlias ​​(). , .

+10

Source: https://habr.com/ru/post/1708127/


All Articles