Game Development Reference
In-Depth Information
This will make sure that when an instance of outline is being created, it creates our
version of it. We override the createChat method in MyOutline as follows:
protected override function createChat():Chat {
return new MyChat();
}
We are now free to implement our own behavior for chat interface.
The text input defined in the Chat class where the player types in the chat message is
set to listen to the event when the user hits the Enter key. The implementation of the
callback simply sends the message to the server as shown below:
public function textEnter(e:Event):void {
var gc:GameClient;
gc = PulseGame.getInstance().getGameClient();
gc.sendChat(m_recipient, m_chat.text);
m_chat.text = "";
}
For the receiving part, the chat message sent via the server is first handled
by PulseGame since it is set up to the Pulse's GameClientCallback . The
implementation simply calls the Chat instance's onChat method. The onChat simply
creates a new string by appending the sender and the message and adds it to the chat
history box as follows:
public function onChat(chat:String, chatter:String):void {
m_history.text = chatter + "> " +
chat + "\n" + m_history.text;
}
There is also a handy method in case we want to output the message to the chat box
called onSystemMessage :
public function onSystemMessage(message:String):void
{
m_history.text = message + "\n" + m_history.text ;
}
This method is useful to output any error message from the server.
 
Search WWH ::




Custom Search