序列化对象的Flex /恢复应用程序状态保存 [英] Serialize Flex Objects to Save/Restore Application State

查看:119
本文介绍了序列化对象的Flex /恢复应用程序状态保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能将序列号的Flex对象的层次,从服务器发送二进制数据到一个URL的存储/检索的/,和反序列化数据恢复的对象原来的状态?

我知道这是可能的对象转换为XML格式(有没有尝试过),但我希望以避免解析XML和手动重建对象。这将是不错的功能,这可以序列化/反序列化对象,以简单的二进制格式(我没有过去在Java中类似的东西,虽然不是很一样容易,我也喜欢)。在Perl的EVAL功能是类似于我在寻找什么,SANS节省code,当然。

在伪code,这里就是我想要做的:

 私人变种contentToSave:使用HBox =新的HBox();

私有函数saveState和(事件:事件):无效{
    VAR toSave:使用HBox = this.contentToSave;
    VAR数据:? = / *连载toSaveActionScript类二进制数据* /;
    sendDataToServer(数据,文件名);
}
私有函数restoreState(文件名):无效{
    VAR数据:? = getDataFromServer(文件名);
    VAR savedData:使用HBox = / *反序列化的二进制数据为ActionScript类* /;
    this.contentToSave = savedData;
}
 

解决方案

在尝试的序列化套餐:// code .google.com / P /的as3corelib /来源/浏览/#SVN /中继/ src目录/ COM /土坯/序列化相对=nofollow> ascorelib

  

[...]但我希望以避免解析XML和手动重建对象

AS处理XML就像任何其他原生类型。放心。 XML是处理数据,你会被脱下,并把后面的服务器上的preferred方式。当然, ascorelib 为您提供了一个JSON类 - 所以你可能想看看那个,以及

  

在Perl中'的eval功能是类似于我在寻找什么,SANS节省当然code,

IIRC,评估是ECMAScript规范的一部分,(你会发现它在Javascript)。但不是在AS3.0。这是有一定程度上的一些previous版(S?),但不再支持。

Is it possible to serialize a hierarchy of objects in Flex, send the binary data to a URL for storage/retrieval on/from a server, and deserialize the data to restore the objects' original state?

I know it's possible to convert the objects into an XML format (haven't tried it yet), but I'm hoping to avoid parsing XML and rebuilding the objects manually. It would be nice to have functionality which can serialize/deserialize objects to a simple binary format (I did something similar in the past in Java, though not quite as easily as I would have liked). The 'eval' function in Perl is similar to what I'm looking for, sans saving code, of course.

In pseudo-code, here's what I would like to do:

private var contentToSave:HBox = new HBox();

private function saveState(event:Event):void {
    var toSave:HBox = this.contentToSave;
    var data:? = /* serialize 'toSave' ActionScript classes to binary data*/;
    sendDataToServer(data, filename);
}
private function restoreState(filename):void {
    var data:? = getDataFromServer(filename);
    var savedData:HBox = /* deserialize binary 'data' to ActionScript classes */;
    this.contentToSave = savedData;
}

解决方案

Try the JSON based serialization package in ascorelib.

[...]but I'm hoping to avoid parsing XML and rebuilding the objects manually

AS handles XML just like any other native type. Rest assured. XML is the preferred way of dealing with data you will be pulling off and putting back on a server. Of course, the ascorelib gives you a JSON class -- so you may want to look at that as well.

The 'eval' function in Perl is similar to what I'm looking for, sans saving code, of course.

IIRC, eval is part of the ECMAScript specification (and you will find it in Javascript). But not in AS3.0. It was there to a certain extent in some previous version(s?) but is no longer supported.

这篇关于序列化对象的Flex /恢复应用程序状态保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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