In this tutorial we will be explaining how to add a sound in the chat component so that when a message is received or sent it will be played.

First of all, open up your application and in the first frame create the code for the sound object that will be played.

You are going to need a sound to play, so go ahead and bring a sound into your library that you would like to be played when you send and/or receive a message . Once you have the sound file imported, right click on it in the library and choose linkage. Enter a name for your sound and press ok.

In this example the name of our sound is 'chimes'

Now we need to create the sound object.

chatSound = new Sound();

The next thing we need to do is make the function that will play the sound.

function playSound(){

Click an instance of the chat component onto the stage, rightClick on it, select 'edit in place' and find the layer called actions. Select the first frame to reveal its code in the actionscript editor.

You have to find the following two functions
FCChatClass.prototype.receiveMessage = function( mesg ) and
FCChatClass.prototype.sendMessage = function(mesg)

You need to add the following line of code to the sendMessage function:

You should also place the following piece of code inside the receiveMessage function. This will check to make sure that the sound does not play when the message is coming from yourself but only when it comes for another user.

The completed code should look like this:
FCChatClass.prototype.receiveMessage = function( mesg ) {
   this.history_txt.htmlText += mesg;
   this.history_txt.scroll = this.history_txt.maxscroll;

FCChatClass.prototype.sendMessage = function(mesg) { "FCChat." + + ".sendMessage", null,    this.message_txt.text );
   this.message_txt.text = "";

You're done. (and keep the sounds subtle or we won't visit your app ;-)