简体   繁体   中英

AS3: Storing array of custom classes in a Locally Shared Object (LSO)

I am having problems storing an array of objects, all of which are the same custom class in an LSO and then reloading that array from the LSO without losing the class type of the objects in the list.

I know how to store a single object of a custom class and load it withe the correct class type using the registerClassAlias() function, but I cannot seem to apply this to arrays of objects.

I am trying to save an array called messageList. Each element is a custom class GameMessage with a property called gameLevel. After I load the LSO I am trying to do something like

trace("0th message is from level " + GameMessage(messageList[0]).gameLevel);

And I am getting an exception of like this:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@90fdfa1 to GameMessage.

I have registered the GameMessage class using

registerClassAlias("GameMessage", GameMessage);

and everything works if rather than a list of messages I try and save/load a single message.

Any help on how to solve this problem would be greatly appreciated!

Like The_asMan said I don't think you can do custom classes, only the basic datatypes from AS3. What you could do in your custom classes is set helper functions like fromObject(object) and toObject():Object in the class to help you convert them.

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