Package | de.maxmaurer.FlashGameCommunicator |
Class | public class FlashGameCommunicator |
Inheritance | FlashGameCommunicator ![]() |
The server as well as this API was written and is copyrighted by Max Maurer. The server application as well as the API may only be used with written permission of the author. Feel free to contact me at: max.maurer (at) stud.ifi.lmu.de
The only thing needed to communicate with the FlashGameCommunicator-Server is an instance of this class. One can issue commands on the server by calling the public methods of this class. Answers from the serer are reported as Events to six different types of EventListeners that can be added to this class.
The first method to call after creating the class and setting up the EventListeners
is the connect
method. For the usage of all the other methods see below.
Each supported Method has a ACTION_...
-Parater assigned to it. The
parameter is returned each time a Event from the server is fired and can be read out
of the EventObject.
A simple call sequence to an exisiting server could look like this:
Property | Defined by | ||
---|---|---|---|
ACTION_CONNECTING : uint = 2 [static] Action asscociated with a connection the is currently established
| FlashGameCommunicator | ||
ACTION_DISCONNECTED : uint = 17 [static] This action is always associated when a disconnected event is reported
| FlashGameCommunicator | ||
ACTION_KICKED : uint = 16 [static] This action is always associated when a kicked event is reported
| FlashGameCommunicator | ||
ACTION_MESSAGE : uint = 14 [static] Action asscoiated with the sendMessage command
| FlashGameCommunicator | ||
ACTION_MESSAGE_LOBBY : uint = 15 [static] Action asscoiated with the sendMessageLobby command
| FlashGameCommunicator | ||
ACTION_MESSAGE_ROOM : uint = 13 [static] Action asscoiated with the sendMessageRoom command
| FlashGameCommunicator | ||
ACTION_MESSAGE_USER : uint = 12 [static] Action asscoiated with the sendMessageUser command
| FlashGameCommunicator | ||
ACTION_ROOM_CREATE : uint = 3 [static] Action associated with the createRoom command
| FlashGameCommunicator | ||
ACTION_ROOM_INFORMATION : uint = 11 [static] Action asscoiated with the roomInformation command
| FlashGameCommunicator | ||
ACTION_ROOM_JOIN : uint = 6 [static] Action asscoiated with the joinRoom command
| FlashGameCommunicator | ||
ACTION_ROOM_LEAVE : uint = 5 [static] Action asscoiated with the leaveRoom command
| FlashGameCommunicator | ||
ACTION_ROOM_LIST : uint = 4 [static] Action asscoiated with the roomList command
| FlashGameCommunicator | ||
ACTION_ROOM_LOCK : uint = 7 [static] Action asscoiated with the lockRoom command
| FlashGameCommunicator | ||
ACTION_ROOM_UNLOCK : uint = 8 [static] Action asscoiated with the unlockRoom command
| FlashGameCommunicator | ||
ACTION_SEND_NAME : uint = 1 [static] Action asscoiacted with the sendName command
| FlashGameCommunicator | ||
ACTION_USER_LIST : uint = 9 [static] Action asscoiated with the userList command
| FlashGameCommunicator | ||
ACTION_USER_LIST_ROOM : uint = 10 [static] Action asscoiated with the userListRoom command
| FlashGameCommunicator | ||
INFO_USER_JOINED : uint = 201 [static] Attached to an incoming information that a user joined the room
| FlashGameCommunicator | ||
INFO_USER_LEFT : uint = 202 [static] Attached to an incoming information that a user left the room
| FlashGameCommunicator | ||
MESSAGE_BROADCAST : uint = 100 [static] Attached to messageType in the GameEvent-Class for all incmoing broadcast Messages
| FlashGameCommunicator | ||
MESSAGE_LOBBY : uint = 101 [static] Attached to messageType in the GameEvent-Class for all incmoing lobby Messages
| FlashGameCommunicator | ||
MESSAGE_PERSONAL : uint = 103 [static] Attached to messageType in the GameEvent-Class for all incmoing personal Messages
| FlashGameCommunicator | ||
MESSAGE_ROOM : uint = 102 [static] Attached to messageType in the GameEvent-Class for all incmoing room Messages
| FlashGameCommunicator |
Method | Defined by | ||
---|---|---|---|
Create a new FlashGameCommunicator object to comunicate with a
FlashGameCommunicator Server
| FlashGameCommunicator | ||
connect(host:String, port:uint):void
Connect to a host and port where a FlashGameCommuncicator-Server is listening
After a successfull connection attempt the connected-Event will be fired
| FlashGameCommunicator | ||
createRoom(name:String, capacity:Number):void
Create and join a new room as a master player.
| FlashGameCommunicator | ||
disconnect():void
Disconnects immedialty from the server.
| FlashGameCommunicator | ||
getConnected():Boolean
This shows if the object is currently connected to a server
| FlashGameCommunicator | ||
getRoomId():Number
Returns the id of the room the user is in
| FlashGameCommunicator | ||
getRoomName():String
Returns the name of the room the user is in
| FlashGameCommunicator | ||
isInRoom():Boolean
Shows if the object is connected and the user has joined a room or if he is still in the lobby
| FlashGameCommunicator | ||
joinRoom(roomId:Number):void
Join a specific room that exists already.
| FlashGameCommunicator | ||
leaveRoom():void
Leave the room the user is currenly in.
| FlashGameCommunicator | ||
lockRoom():void
Lock the room.
| FlashGameCommunicator | ||
roomInformation(roomId:Number):void
Get more information on a certain room.
| FlashGameCommunicator | ||
roomList():void
Get a list from the server with all rooms avaiable
The list ist returned in the dataArray of the GameEvent.
| FlashGameCommunicator | ||
sendMessage(message:String):void
Send a broadcast message to all players on the server.
| FlashGameCommunicator | ||
sendMessageLobby(message:String):void
Send a message only to everyone in the lobby.
| FlashGameCommunicator | ||
sendMessageRoom(message:String):void
Send a message to all the players in the same room
The player himself will not receive the message again.
| FlashGameCommunicator | ||
sendMessageUser(message:String, userId:Number):void
Sent a message only to a specific user on the server.
| FlashGameCommunicator | ||
sendName(name:String):void
Change the name of the user on the server.
| FlashGameCommunicator | ||
setDebug(b:Boolean):void
| FlashGameCommunicator | ||
unlockRoom():void
Unlock a room that has been previously locked.
| FlashGameCommunicator | ||
userList():void
Get a list of all the users in the lobby (that means users that are not in a room).
| FlashGameCommunicator | ||
userListRoom(roomId:Number):void
Get a list of all players in the current room.
| FlashGameCommunicator |
ACTION_CONNECTING | property |
public static var ACTION_CONNECTING:uint = 2
Action asscociated with a connection the is currently established
See also
ACTION_DISCONNECTED | property |
public static var ACTION_DISCONNECTED:uint = 17
This action is always associated when a disconnected event is reported
See also
ACTION_KICKED | property |
public static var ACTION_KICKED:uint = 16
This action is always associated when a kicked event is reported
See also
ACTION_MESSAGE | property |
public static var ACTION_MESSAGE:uint = 14
Action asscoiated with the sendMessage command
See also
ACTION_MESSAGE_LOBBY | property |
public static var ACTION_MESSAGE_LOBBY:uint = 15
Action asscoiated with the sendMessageLobby command
See also
ACTION_MESSAGE_ROOM | property |
public static var ACTION_MESSAGE_ROOM:uint = 13
Action asscoiated with the sendMessageRoom command
See also
ACTION_MESSAGE_USER | property |
public static var ACTION_MESSAGE_USER:uint = 12
Action asscoiated with the sendMessageUser command
See also
ACTION_ROOM_CREATE | property |
public static var ACTION_ROOM_CREATE:uint = 3
Action associated with the createRoom command
See also
ACTION_ROOM_INFORMATION | property |
public static var ACTION_ROOM_INFORMATION:uint = 11
Action asscoiated with the roomInformation command
See also
ACTION_ROOM_JOIN | property |
public static var ACTION_ROOM_JOIN:uint = 6
Action asscoiated with the joinRoom command
See also
ACTION_ROOM_LEAVE | property |
public static var ACTION_ROOM_LEAVE:uint = 5
Action asscoiated with the leaveRoom command
See also
ACTION_ROOM_LIST | property |
public static var ACTION_ROOM_LIST:uint = 4
Action asscoiated with the roomList command
See also
ACTION_ROOM_LOCK | property |
public static var ACTION_ROOM_LOCK:uint = 7
Action asscoiated with the lockRoom command
See also
ACTION_ROOM_UNLOCK | property |
public static var ACTION_ROOM_UNLOCK:uint = 8
Action asscoiated with the unlockRoom command
See also
ACTION_SEND_NAME | property |
public static var ACTION_SEND_NAME:uint = 1
Action asscoiacted with the sendName command
See also
ACTION_USER_LIST | property |
public static var ACTION_USER_LIST:uint = 9
Action asscoiated with the userList command
See also
ACTION_USER_LIST_ROOM | property |
public static var ACTION_USER_LIST_ROOM:uint = 10
Action asscoiated with the userListRoom command
See also
INFO_USER_JOINED | property |
public static var INFO_USER_JOINED:uint = 201
Attached to an incoming information that a user joined the room
INFO_USER_LEFT | property |
public static var INFO_USER_LEFT:uint = 202
Attached to an incoming information that a user left the room
MESSAGE_BROADCAST | property |
public static var MESSAGE_BROADCAST:uint = 100
Attached to messageType in the GameEvent-Class for all incmoing broadcast Messages
MESSAGE_LOBBY | property |
public static var MESSAGE_LOBBY:uint = 101
Attached to messageType in the GameEvent-Class for all incmoing lobby Messages
MESSAGE_PERSONAL | property |
public static var MESSAGE_PERSONAL:uint = 103
Attached to messageType in the GameEvent-Class for all incmoing personal Messages
MESSAGE_ROOM | property |
public static var MESSAGE_ROOM:uint = 102
Attached to messageType in the GameEvent-Class for all incmoing room Messages
FlashGameCommunicator | () | constructor |
public function FlashGameCommunicator()
Create a new FlashGameCommunicator object to comunicate with a FlashGameCommunicator Server
connect | () | method |
public function connect(host:String, port:uint):void
Connect to a host and port where a FlashGameCommuncicator-Server is listening After a successfull connection attempt the connected-Event will be fired
Parametershost:String — A String containing an IP-Adress or hostName of a host to conncet to
|
|
port:uint — A port number bigger than 1024 where the server is listening on
|
— Throws an Error if you try to call this function when a connection has already been established
|
createRoom | () | method |
public function createRoom(name:String, capacity:Number):void
Create and join a new room as a master player. After the success full creation the room will show up on the room list. A room exists as long as the master player does not leave it. If he does the room is closed and all other players in the room are kicked.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
name:String — A name for this room
|
|
capacity:Number — How many players should be in the room. The room master count as a player too. That's why 1 is the minimum here. Than the room is immedialty full.
|
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player still is in a room
|
See also
disconnect | () | method |
public function disconnect():void
Disconnects immedialty from the server. There will be no SUCCESS or FAILED event on this. Normally a disconnect event should be fired immediately after this action took place.
— An error is thrown if there is no connection to the server
|
getConnected | () | method |
public function getConnected():Boolean
This shows if the object is currently connected to a server
ReturnsBoolean — true if connected to a server or false if disconnected
|
getRoomId | () | method |
public function getRoomId():Number
Returns the id of the room the user is in
ReturnsNumber — the id of the room the user is in or 0 if the user is not connected to any room
|
— An error is thrown if there is no connection to the server
|
getRoomName | () | method |
public function getRoomName():String
Returns the name of the room the user is in
ReturnsString — the name of the room the user is in or null if the user is not connected to a room or the room name can not be identified
|
— An error is thrown if there is no connection to the server
|
isInRoom | () | method |
public function isInRoom():Boolean
Shows if the object is connected and the user has joined a room or if he is still in the lobby
ReturnsBoolean — true if the user is still in the lobby
|
— An error is thrown if there is no connection to the server
|
joinRoom | () | method |
public function joinRoom(roomId:Number):void
Join a specific room that exists already. The join will fail if the capacity of this room has already been reached or if the room is locked. When the join is successfull the roomId and roomName will be set in the GameEvent-Object.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
roomId:Number — The roomId of the room the user wants to join
|
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player still is in a room
|
See also
leaveRoom | () | method |
public function leaveRoom():void
Leave the room the user is currenly in. If the user is the master user of this room, the room will be closed and all other players will be kicked.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player is not in a room
|
See also
lockRoom | () | method |
public function lockRoom():void
Lock the room. If a room is locked nobody else can join it. Locking is only available to the player who created the room. If any other player tries to lock the room the lock will fail. Use unlockRoom() to revert this. To see wether a room is locked or not you can use roomInformation().
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player is not in a room
|
See also
roomInformation | () | method |
public function roomInformation(roomId:Number):void
Get more information on a certain room. The GameEvent returned on this command will have set the parameters roomName, roomCapacity, roomSize and roomLocked.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
roomId:Number — The id of a room on the server if no id is specified the information of the current room the user is in will be returned
|
— An error is thrown if there is no connection to the server
|
See also
roomList | () | method |
public function roomList():void
Get a list from the server with all rooms avaiable The list ist returned in the dataArray of the GameEvent. For more Information see the description of dataArray in the GameEvent class.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
— An error is thrown if there is no connection to the server
|
See also
sendMessage | () | method |
public function sendMessage(message:String):void
Send a broadcast message to all players on the server. Every player will receive it even if the player is in locked room. Broadcast messages should be used thoughtfully. The player himself will not receive the message again. Instead he will receive a success event, when the message has been delivered completly.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
message:String — The message to be sent
|
— An error is thrown if there is no connection to the server
|
See also
sendMessageLobby | () | method |
public function sendMessageLobby(message:String):void
Send a message only to everyone in the lobby. The player himself will not receive the message again. Instead he will receive a success event, when the message has been delivered completly.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
message:String — The message to be sent
|
— An error is thrown if there is no connection to the server
|
See also
sendMessageRoom | () | method |
public function sendMessageRoom(message:String):void
Send a message to all the players in the same room The player himself will not receive the message again. Instead he will receive a success event, when the message has been delivered completly.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
message:String — The message to be sent
|
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player is not in a room
|
See also
sendMessageUser | () | method |
public function sendMessageUser(message:String, userId:Number):void
Sent a message only to a specific user on the server. The user only needs to be online. Its not necessary that he is in the same room and he will receive the message even if the room he is in is locked. The player himself will not receive the message again. Instead he will receive a success event, when the message has been delivered completly.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
message:String — The message to be sent
|
|
userId:Number — The Id of the user who should receive the message
|
— An error is thrown if there is no connection to the server
|
See also
sendName | () | method |
public function sendName(name:String):void
Change the name of the user on the server. After a connection to the server the user name is not defined and will be given as a String containing "null" each time a userName is requested
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
name:String — The new name for this player
|
— An error is thrown if there is no connection to the server
|
See also
setDebug | () | method |
public function setDebug(b:Boolean):void
Parameters
b:Boolean |
unlockRoom | () | method |
public function unlockRoom():void
Unlock a room that has been previously locked. If a room is locked nobody else can join it. Locking is only available to the player who created the room. If any other player tries to lock the room the lock will fail. Use unlockRoom() to revert this. To see wether a room is locked or not you can use roomInformation().
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player is not in a room
|
See also
userList | () | method |
public function userList():void
Get a list of all the users in the lobby (that means users that are not in a room). The list ist returned in the dataArray of the GameEvent. For more Information see the description of dataArray in the GameEvent class.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
— An error is thrown if there is no connection to the server
|
See also
userListRoom | () | method |
public function userListRoom(roomId:Number):void
Get a list of all players in the current room. The first player on the list is always the master player of this room. The list is returned in the dataArray of the GameEvent. For more Information see the description of dataArray in the GameEvent class.
This method has no return value instead a SUCCESS or FAILED event is fired depending on what
the server answer to this request was. The GameEvent always contains the corresponding ACTION_...
-Type
in the messageType
Parameter.
roomId:Number — The id of a room on the server if no id is specified the information of the current room the user is in will be returned
|
— An error is thrown if there is no connection to the server
|
|
— An Error is also thrown if the player is not in a room
|
See also