GODPAPER | All Packages | All Classes | Index | Frames No Frames |
Connection

Package | playerio
Interface | public interface Connection

Allows the client to connect to the Multiplayer servers

Public Properties

| Property | Defined By
--- | --- | ---
|  | connected : Boolean [read-only] Returns the connection's connected status | Connection

Public Methods

| Method | Defined By
--- | --- | ---
|  | addDisconnectHandler(handler:Function):void Listen to server disconnects. | Connection
|  | addMessageHandler(type:String, handler:Function):void Add listener for messages of a specified type | Connection
|  | createMessage(type:String, ... args):Message Creates a Message instance | Connection
|  | disconnect():void Disconnects from the server | Connection
|  | removeDisconnectHandler(handler:Function):void Removes a handler previously attached with addDisconnectHandler | Connection
|  | removeMessageHandler(type:String, handler:Function):void Removes a message handler previously attached with addMessageHandler | Connection
|  | send(type:String, ... args):void Quick way to send messages to the server | Connection
|  | sendMessage(message:Message):void Sends a message to the server | Connection

Property Detail

connected | property

`connected:Boolean` [read-only]

Returns the connection's connected status

Implementation
`public function get connected():Boolean`
Method Detail

addDisconnectHandler | () | method

`public function addDisconnectHandler(handler:Function):void`

Listen to server disconnects. This method is only called if we are disconnected by the server. A call to connection.disconnect will not trigger this method.

Parameters

| `handler:Function` — Callback to execute if disconnected from the server.

addMessageHandler | () | method |

`public function addMessageHandler(type:String, handler:Function):void`

Add listener for messages of a specified type

Parameters

| `type:String` — String that defines what type to listen to. If sat to " the listener will listen to all message types
| `handler:Function` — Callback method executed when a message of the type specified is recived: function(m:Message):void{...} or function(m:Message, messageValye1:Type, messageValye1:Typ, ... ):void{...}

Example
Shows how to define a message listener

             connection.addMessageHandler("move", function(m:Message):void{
                 trace("Moved to", m.getInt(0), m.getInt(1))
             })

Shows how to define a message listener with inline arguments

             connection.addMessageHandler("move", function(m:Message, x:int, y:int):void{
                 trace("Moved to", x, y)
             })

createMessage | () | method |

`public function createMessage(type:String, ... args):Message`

Creates a Message instance

Parameters

| `type:String` — The type of the message
| `... args` — Data entries we should add to the message when we create it

Returns

| `Message` — A Message instance

disconnect | () | method |

`public function disconnect():void`

Disconnects from the server

removeDisconnectHandler | () | method |

`public function removeDisconnectHandler(handler:Function):void`

Removes a handler previously attached with addDisconnectHandler

Parameters

| `handler:Function` — Callback we wish to remove the listener for.

removeMessageHandler | () | method |

`public function removeMessageHandler(type:String, handler:Function):void`

Removes a message handler previously attached with addMessageHandler

Parameters

| `type:String` — String that defines what type we wish to stop listening to
| `handler:Function` — Callback we wish to remove the listener for

send | () | method |

`public function send(type:String, ... args):void`

Quick way to send messages to the server

Parameters

| `type:String` — The type of the message we want to send
| `... args` — Data entries that should be added to the message

sendMessage | () | method |

`public function sendMessage(message:Message):void`

Sends a message to the server

Parameters

| `message:Message` — Message to send to the server

Thu Jan 16 2014, 01:11 PM +08:00