哪些数据类型做了共享对象的支持? [英] What data types does a SharedObject support?

查看:151
本文介绍了哪些数据类型做了共享对象的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是一个简单的事情来存储字符串和数字用一个共享对象,并且我也熟悉了这样的事情:

I know it is a simple matter to store Strings and Numbers with a SharedObject, and I am also familiar with this sort of thing:

var sharedObject:SharedObject = SharedObject.getLocal("userData");
var obj:Object = new Object();
obj.prop = "value";
sharedObject.data.userobj= obj;
sharedObject.flush();

不过,我试图存储类GameStage的对象,一类我已经定义保存有关阶段的数据在我的游戏。好像没有这种类型的事情并不奏效:

However, I am attempting to store an object of the class GameStage, a class I have defined to hold data about stages in my game. This type of thing doesn't seem to be working:

var sharedObject:SharedObject = SharedObject.getLocal("userData");
var stageOne:GameStage = new GameStage();
stageOne.highScore = 99999;
sharedObject.data.stageOne = stageOne;
sharedObject.flush();

这code没有引发错误,但是当我试图再次找到舞台的数据,像这样:

This code doesn't throw an error, but when I try to retrieve the stage data later, like so:

stageOne = sharedObject.data.stageOne;

我得到这个错误:

I get this error:

TypeError: Error #1034: Type Coercion failed: cannot convert Object@3d220629 to GameStage.

我想我的问题是:究竟什么样的数据类型都可以存储在共享对象?无论我已经在网上看了看已经回答了这个问题有,这是不是很描述任何可以在Flash中使用 - 显然我GameStage类的工作中闪光过。是否有一些关于从共享对象,我不知道检索数据?

I guess my question is: exactly what sort of data types can be stored in a SharedObject? Everywhere I've looked online has answered that question with "anything that can be used in Flash", which isn't very descriptive – obviously my GameStage class works in Flash too. Is there something about retrieving data from the SharedObject that I'm not aware of?

我的prediction的是,我将无法保存我的舞台数据这种方式。如果是这样的话,任何人都可以建议保存数据的另一种方法

My prediction is that I will not be able to store my stage data this way. If that is the case, could anyone suggest an alternative method to saving the data?

推荐答案

您可以存储任何对象在的共享对象,但你需要先注册类:

You can store any object in a SharedObject, but you need to register the class first:

您可以存储类型化动作   在共享对象实例。你做   这通过调用   flash.net.registerClassAlias​​()方法   注册类。如果您创建   你的类的实例,并存储   在共享的数据成员   对象,以后要阅读的对象了,   你会得到一个类型的实例。通过   默认情况下,共享对象   objectEncoding属性支持AMF3   编码和解压您的存储   例如从SharedObject对象;   存储的实例保留相同   键入当你调用指定   registerClassAlias​​()方法。

You can store typed ActionScript instances in shared objects. You do this by calling the flash.net.registerClassAlias() method to register the class. If you create an instance of your class and store it in the data member of your shared object and later read the object out, you will get a typed instance. By default, the SharedObject objectEncoding property supports AMF3 encoding, and unpacks your stored instance from the SharedObject object; the stored instance retains the same type you specified when you called the registerClassAlias() method.

一个需要注意的是,存储对象图形有时会导致存储问题。是有限制多少可以在共享对象存储之前它通知用户,并询问许可存储更多。此阈值是100K的默认情况下,我相信。

One caveat is that storing object graphs can sometimes lead to storage issues. There is a limit to how much you can store in SharedObject before it notifies the user and asks for permission to store more. This threshold is 100k by default, I believe.

这篇关于哪些数据类型做了共享对象的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆