AS3:在本地共享对象(LSO)中存储自定义类数组
我在存储对象数组时遇到问题,所有这些对象在 LSO 中都是相同的自定义类,然后从 LSO 重新加载该数组,而不会丢失列表中对象的类类型。
我知道如何存储自定义类的单个对象并使用 registerClassAlias()
函数使用正确的类类型加载它,但我似乎无法将其应用于对象数组。
我正在尝试保存一个名为 messageList 的数组。每个元素都是一个自定义类 GameMessage,具有名为 gameLevel 的属性。加载 LSO 后,我尝试做类似的事情
trace("0th message is from level " + GameMessage(messageList[0]).gameLevel);
,但我遇到了这样的异常:
TypeError:错误#1034:类型强制失败:无法将 Object@90fdfa1 转换为 GameMessage。
我已经使用注册了 GameMessage 类
registerClassAlias("GameMessage", GameMessage);
,如果我尝试保存/加载单个消息而不是消息列表,则一切正常。
任何有关如何解决此问题的帮助将不胜感激!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就像 The_asMan 所说,我不认为你可以做自定义类,只能做 AS3 的基本数据类型。您可以在自定义类中执行的操作是在类中设置辅助函数,例如 fromObject(object) 和 toObject():Object 来帮助您转换它们。
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.