Sign in

Forgot your
password?

Message

Namespace: Nonoba.api
Language: ActionScript 3

Message object used to parse data back and forward to the server.

When data is received from the server it will be wrapped in a message object. Likewise a message object can be send to the server.

Lets initialize the multiplayer API and send a message to the server as an example.

//Initialize the multiplayer API (You can only do this once)
var connection:Connection = NonobaAPI.MakeMultiplayer(stage);

// Create a message
var m = new Message("testmessage");
m.Add("Data 1");
m.Add(2)
m.Add(true)

//Send message to server
connection.Send(m);

Public Properties

Type:String
The type of the message.

length:String
How many data entries are stored in the message.

Constructor

Message(type:String, [...args:*])
Create a new message of the given type. After the type any amount as data can be added as the rest arguments.

Public Methods

Add(...args:*):void
Ads any amount of data of any type to the message.

GetNumber(index:int):Number
Read position index as a Number.

GetInt(index:int):Int
Read position index as an Int.

GetString(index:int):String
Read position index as a String.

GetBoolean(index:int):Boolean
Read position index as a Boolean.

GetByteArray(index:int):ByteArray
Read position index as a ByteArray (This it not yet fully supported).

Clone(target:Object):void
Copies the data inside the message to another object.

toString():String
Prints the message in an easy to read format.

Details

Add method

public function Add(...args:*):void
Ads any amount of data of any type to the message.

Example
//Create a message
var m = new Message("testmessage");

//Add a single string to the message
m.Add("Data 1");

//Add two more strings to the message
m.Add("Data 2", "Data 3");

//Trace the final message object
trace(m);

GetNumber method

public function GetNumber(index:int):Number
Read position index as a Number.

GetInt method

public function GetInt(index:int):Int
Read position Int as an Int.

GetString method

public function GetString(index:int):String
Read position index as a String.

GetBoolean method

public function GetBoolean(index:int):Boolean
Read position index as a Boolean.

GetByteArray method

public function GetByteArray(index:int):ByteArray
Read position index as a ByteArray.

Clone method

public function Clone(target:Object):void
Copies the data inside the message to another object.

toString method

public function toString():String
Prints the message in an easy to read format.

Example

The below example shows a full document class for a FLA file which initializes the multiplayer API, sends a message and attach to all events

	
//Create a message
var m = new Message("testmessage");

//Add a single string to the message
m.Add("Data 1");

//Add two more strings to the message
m.Add("Data 2", "Data 3");

//Trace a the string in position 2
trace(m.GetString(1));

//Trace the final message object
trace(m);
 
NONOBA-WEB2