Simple Chat with Adobe AIR using GameClientSDK Communication API


This is a very simple chat application developed using the GameClientSDK.
There are 2 important components here:


<Communication:ServerCommunication id="client" GuestLogin="true" ExpansionID="TestExpansion" ConnectNow="true" />
and
<Rooms:Room id="room" ServerComm="{client}" RoomID="AnyRoomName" onRPC="this.textChat.text += event.RpcParameters.FetchParameterValue('userName') + ': ' + event.RpcParameters.FetchParameterValue('chatMessage') + '\n'"/>
We only write one actionscript function to handle the enter event of the textinput. Here we send the text to people in the room.
protected function OnEnter():void
{
var params:ParameterCollection = new ParameterCollection();
params.AddParameter("chatMessage",this.textInput.text);
params.AddParameter("userName", this.client.LoggedInUser.UserName);

this.room.MakeRoomRPC("anyfunction", params);

this.textInput.text = "";
}
You can view the source codes here.
You can test the application here.

No comments: