Simple Chat in AS3 help!

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

didibus
Posts: 34
Joined: 09 Sep 2007, 19:31

Simple Chat in AS3 help!

Postby didibus » 14 Sep 2007, 04:08

Hi,

I'm trying to port the simpleChat example from the docs to flash CS3 AS3.

I'm having a very weird problem. When I click the login button, it goes to the chat frame but doesn't seem to execute the code on the layer, at least most of the time. Because some time it works, but 90% of the time it doesn't. I found out that if I click the login really quickly it has more chances of working. If I press it a bit longer it fails a lot.

If someone could help me out, I just don't get it, same code works sometimes, fail other times.

Here's the source:
Right-Click and Save as. You'll need Flash CS3 for this.

http://aglocoinfo.freehostia.com/simple_chat.fla
didibus
Posts: 34
Joined: 09 Sep 2007, 19:31

Postby didibus » 14 Sep 2007, 05:06

I think it might have something to do with event listeners. I tried changing:
sfs.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate); by putting it on the connect frame instead and now it works 60% of the time, but still not 100%.
didibus
Posts: 34
Joined: 09 Sep 2007, 19:31

Postby didibus » 17 Sep 2007, 02:09

Well, I found a fix to solve the problem.
So forget this thread
User avatar
Bax
Site Admin
Posts: 4612
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Postby Bax » 17 Sep 2007, 06:54

Can you please post the solution to your problem, in case other users experience the same? Thank you.
Paolo Bax
The SmartFoxServer Team
didibus
Posts: 34
Joined: 09 Sep 2007, 19:31

Postby didibus » 25 Sep 2007, 21:17

I'll explain the cause of the problem and the solution I found which might not be the best, but I think it's pretty close.

The problem is caused by the onRoomListUpdate listener. In the simpleChat example, you split the code on 2 frames, one holds the Connect code and UI and the other holds the Chat code and the UI. The problem is that you need to listen for the onRoomListUpdate on the Connect frame, but you need to join the desired room on the Chat frame so that it updates the Chat UI after it has been loaded.

The solution in AS3 is to create the onRoomListUpdate listener on the Connect frame have the function switch a boolean then gotoAndStop to the chat frame and on the chat frame put a if boolean is true then join the room. This way you can delay the event execution to when your certain the UI has been loaded.

Connect frame :

Code: Select all

var g_isOnRoomListUpdate:Boolean = false;
sfs.addEventListener(SFSEvent.onRoomListUpdate, onRoomListUpdate);

function onRoomListUpdate(evt:SFSEvent):void
{
   g_isOnRoomListUpdate = true;
   trace("onRoomListUpdate: We got the Room List");
   gotoAndStop("chat");
}


Chat frame :

Code: Select all

if (g_isOnRoomListUpdate == true)
{
   trace("g_isOnRoomListUpdate is true!");
   sfs.autoJoin();
}

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 40 guests