本文介绍了序列化圆形对象的网络使用的writeObject /的readObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我即将实施

public function writeExternal( output:IDataOutput ):void {...}
public function readExternal( input:IDataInput ):void {...}

做一组对象的序列化。

to make a set of object serializable.

虽然我是pretty的肯定,我实现了所有正确的,的readExternal(..)在某一点抱怨太少数据留下来读:

Although I'm pretty sure, that I implemented all correctly, readExternal(..) at a certain point complains about too few data left to read:

RangeError: Error #2006: The supplied index is out of bounds.
    at flash.filesystem::FileStream/readObject()

我在想,如果我有像

I wonder, if I have a circular object network like

A = { left -> B, right -> B }
B = { father -> A }

和我称之为

writeObject( a )

将Flex的孔对象序列化网络的每个对象一次,只有一个?

will Flex serialize the hole object network and each object once and only one?

我这样做:

  • 在声明类型注释是这样的: [为RemoteClass(别名为model.MyClass)]
  • 实现无参数的构造函数
  • 在申报使用的所有类实现IExternalizable
  • Declared type annotations like this: [RemoteClass(alias="model.MyClass")]
  • Implemented parameter-free constructors
  • Declared all classes using implements IExternalizable

共享对象的发()方法是保证发送每个对象一次且仅一次。

SharedObject's send() method is guaranteed to send each object once and only once.

其他的相关信息:

  • 读取和写入ByteArray
  • 使用远程对象组件
  • <一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/IExternalizable.html?filter_flex=4.1&filter_flashplayer=10.2&filter_air=2.6"相对=nofollow> IExternalizable 接口
  • Reading and writing a ByteArray
  • Using Remote Object Components
  • IExternalizable interface

请看看这个related问题。

推荐答案

荟萃[为RemoteClass]是的,只能用于该Flex编译器识别为使用Flex框架的项目中使用的类的指令。它基本上等同于调用 registerClassAlias​​(MyClass的,model.MyClass); 由于一些原因,延长这个话题的能力,我建议你使用registerClassAlias​​代替。

The meta [RemoteClass] is an instruction for and only for classes used in projects that Flex compiler identifies as using Flex framework. It is basically equivalent to calling registerClassAlias(MyClass, "model.MyClass"); For a number of reasons that extend the capacity of this topic, I'd suggest that you use registerClassAlias instead.

关于AMF内置的作家,其行为如下:如果writer接收它需要编写的所有对象的一次的(如在一棵树,你给它的根节点),然后它会写完全的对象只有一次,引用该对象出现的下一个时间,它会使用参考。但是,如果你不断地给它的对象,这可能已经被引用的(如通过连续调用的writeExternal),它会对待每一个对象,就好像它是新的。至少在理论上,它应该工作的另一种方式了。即如果该对象被作为参考序列,它们一旦反序列化,应使用的参考。这将有助于看到您更多的code,的writeExternal和readExternal特别的实施给一个更好的答案。

Regarding AMF built-in writer, the behavior is as follows: if the writer receives all objects it needs to write at once (as in a tree, you give it the root node), then it will write fully the object only once, the next time the reference to that object appears, it will use the reference. However, if you continually feed it objects, which may have already been referenced (such as through successive calls to writeExternal) it will treat every object as if it was new. At least theoretically, it should work the other way too. That is if the objects were serialized by reference, once they deserialized, the reference should be used. It would help to see more of your code, particularly the implementation of writeExternal and readExternal to give a better answer.

这篇关于序列化圆形对象的网络使用的writeObject /的readObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:23