Entry: red5 chat
Description
This simple chat uses the Red5 server which is an open source alternative to the quite expensive Flash Media Server. If you want to try the code yourself get the server from http://osflash.org/red5. It's available for Windows and several linux distributions, so you should have no problems istalling the server on your localhost and test it.
The server comes with some good examples already but they are structured in a way that they look more complex than they really are so I rebuild a simple chat to show that you basically need only a few lines to make a chat work. We will use a SharedObject to save the conversation.
var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/test");
var remote_so:SharedObject = SharedObject.getRemote("chat", nc.uri, false);
remote_so.connect(nc);

function sendMessage(){
remote_so.data.chatText += "\n" + "<b>" + username + "</b>: " + ChatInput.text;
}

remote_so.onSync = function(list){
if (remote_so.data.chatText != undefined){
ChatOutput.text = remote_so.data.chatText;
}
}
First we create a NetConnection object (after installing the red5 server you could use the "test" application that comes with red 5 to test your code), then we connect to an application on the server using rtmp.
Then we create a remote SharedObject on the server which is called "chat", uses the uri from the connection and is intended to not be permanent. Then we can connect to that object.
As the user types in a message we simply write the message string to the remote_so.data.chatText field which then is sent to all connected clients.
Whenever the SharedObject is changed the onSync event of the remote_so object is fired. In this case we simply append the data stored in the chatText field of the SharedObject to the chat window.

I simplified the code a little bit, the downloadable AS2 source code is complete. I only used AS2 because I was too lazy to create my own components by now as they are not out for Flash 9 while I am writing this. The AS3 code should be almost the same.
download source
Comments
sudo wrote:
Free red5 video chat: http://www.freedevelopment.net/articles/free-red5chat.html
Markus wrote:
hi bros happy that their is a site where we can talk about the red5 chat guys, can someone please, help me to make a room list with List Component.

Hope yes
bye waiting
Dennis wrote:
Hey bro im trying to write the code in As 3 but have got some probs can you help their please ?


Thank you
Xenofon wrote:
Do have any solution about the ChatOutput schroll ?

NameE-Mail
send


Creative Commons License