简体   繁体   中英

Saving custom class /w object to local SharedObject

I have a custom class that I have been saving to a local SharedObject with no problems after using registerClassAlias.

registerClassAlias("MyClass",MyClass);

MyClass's variables are all private, and I read that private variables are not serialized unless they use explicit setters and getters, which fortunately MyClass uses for all private variables. Now I want to add another private variable to MyClass - a generic object:

private var myObject:Object = new Object();

The problem is that I can't use explicit setters and getters with myObject if I want to do something like:

myObject["day"] = "Monday";

And because the private variable myObject doesn't use setters and getters, nothing in myObject is retrievable when MyClass is loaded. It turns out that the easiest fix is to make myObject public instead of private and everything works. But I was wondering what would be the right way to keep myObject private and have it serialize properly?

按照此处所述使用ByteArray。http: //jacksondunstan.com/articles/1642

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM