views:

241

answers:

1

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

+2  A: 

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.

Joa Ebert