2

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

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.