I recently ran into a real mess when trying to persist a typed singleton object in a Flex Mobile application via the PersistenceManager class.
DevGirl Holly Schinsky has a great blog post on managing data in a Flex Mobile application, and I was specifically using her instructions on persisting typed objects. The basics are this:
1.) Register the class alias
flash.net.registerClassAlias("person",model.Person);
2.) Get an instance of the PersistenceManager class
var persistenceManager : PersistenceManager = new PersistenceManager();
3.) Save the object to be persisted
persistenceManager.setProperty("savedData", _personInstance);
persistenceManager.save();
4.) Re-load the object at a later time
persistenceManager.getProperty("savedData");
Everything works totally fine UNLESS the object you're persisting has a hidden internal class - a class who's scope is internal to the model object class itself. This is often the case for singleton classes in AS3 - since there's no way to make a private constructor the best-practice for singletons in AS3 is to make the constructor take an instance of an internal class object so that no external classes can call the constructor.
I suspect the error is during de-serialization - since the serializer can't make an instance of your singleton model's internal class, it can't make the model class itself at all, and de-serialization fails.
For now I'm just removing the internal classes from my singleton. It means it's no longer really secure, but I'll take the easy data persistence and built-in serialization of the PersistenceManager over having to do the serializing/de-serializing myself.
I suspect this would be an issue with any AMF serialization in Flash - I bet these types of locked singleton's can't be persisted across the client/server or to a regular LSO or anything like that either.
Saturday, July 2, 2011
Thursday, April 14, 2011
Amazing client quote
Regarding EUI's work for Pearson recently, the product manager for our client said:
Wow, that's amazing feedback. It feels great to be a part of the EffectiveUI team when we get this sort of feedback. :)
“Each of you probably had your own reasons for getting into this business, but I'm sure the hope was improving people's lives. That's what you've done here, one student, one class, one non-missed exam at a time. That's something to be proud of.”
Wow, that's amazing feedback. It feels great to be a part of the EffectiveUI team when we get this sort of feedback. :)
Tuesday, January 18, 2011
HTML5 Logo Background Images
Subscribe to:
Posts (Atom)