I am trying to pass object to the server through socket connection in actionscript 3. What is the best way to do that?
is serialization better? or should I encode it first and then sent it as string?
please help me to understand this?
开发者_如何学编程thank you
If your object is implementing IExternalizable and you call registerClassAlias you are safe to use readObject and writeObject. Note however that no constructor parameters are allowed when implementing IExternalizable.
For instance:
package {
import flash.net.*;
import flash.utils.*;
public class Foo implements IExternalizable {
registerClassAlias("Foo", Foo);
public var bar: String;
public function Foo() { // No constructor parameters allowed.
}
public function writeExternal(output: IDataOutput): void { output.writeUTF(bar); }
public function readExternal(input: IDataInput): void { bar = input.readUTF(); }
}
}
You are then safe to call readObject and writeObject on any IDataOutput or IDataInput which is for instance a Socket, ByteArray or URLStream.
精彩评论