Monday, January 24, 2011

SmartFoxServer Tutorial: Chat Log

Hello everyone!

It's been a while since I posted on this site. I'm sorry about that, I've just been a little busy on a new project I'm working on. Anyway, as you can tell from the post title, this tutorial is on how to create a chat log. The chat log we create in this tutorial will have an auto-scrolling feature. Anyway, let's get started!

First things first, I'm using an avatarChat example file from SmartFoxserver. So, let's go ahead and open that file up.

After the file is opened, go to the 'chat' frame and put a dynamic text box on the stage and give it an instance name of chatLog and make sure you tick the box shown below so that it has HTML abilities.

After you do that, you need to open up the 'chat' frame's coding. After the coding is up, scroll down until you find a SmartFoxServer handler called "smartfox.onPublicMessage." Add this coding inside that handler:

//New Chat Log Coding:
//--Basic Add Message Coding:
chatLog.htmlText += user.getName() + ": " + msg + newline; //Add text to textbox
//--Basic Auto-Scroll Coding:
var logVar = 1; //Creates a variable, you might want to increase this
chatLog.scroll = logVar; //Scrolls textbox to variable amount
logVar++; //Increases variable value

Pretty basic coding, as you can see. Here is an image of where I added that coding in my Flash file:

(Coding in the image isn't correct, use the coding as shown above!)

Well, after you do that, test the movie and it should be working fine.

If you encounter any problems with this be sure to leave a comment and I'll get back to you as soon as I can.

Source File: Download


  1. When I say a message it works fine.But when I see multiple messages, it looks like this:


    Do you know how to fix this? Thanks

    ~Guy71173 :P

  2. Guy71173: Ah yes. Thanks for reporting that glitch. I didn't test my own movie before posting this as you can see. I'll fix that now.

  3. Mine doesn't scroll after there are like 8 lines.
    Can you help?

  4. MrFrozenCake: Change the line "logVar++;" to the following:

    logVar += 10;

    It doesn't have to be 10, it's just an example of a more increased number.

  5. My friend,wich has a vw too,has the same problem,we both need help

  6. I tired your fla,the source you gave.
    I goes
    Andy: 1
    Andy: 2
    Andy: 3
    Andy: 4
    Andy: 5
    When i type a message after that 5 lines,nothing shows up.
    Rewite the code please!

  7. MrFrozenCake: I posted this coding because this is what I had in an old file of mine. I tested this on CS5 and it didn't work. To fix it, I used this:

    chatLog.scroll = logVar;

  8. how come it shows up 3 times?

  9. @Anonymous: Your question isn't very clear to me. When you say 'it', what are you talking about exactly?

  10. Can you reupload all of your files? It would be greatly appreciated.

    1. Please read the update to the newest post! Specify SFS2X or SFS1X!