User 1 is opening the application from Flash and user 2 from browser
... and I get this error:
[ RECEIVED ]:
<msg t='sys'><body action='uCount' r='2' u='1'></body></msg>
, (len: 60)
[ RECEIVED ]: <msg t='sys'><body action='userGone' r='89'><user id='91' />
, (len: 73)
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleUserLeaveRoom()[/Users/Lapo/Documents/Flex Builder 2/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/handlers/SysHandler.as:353]
at Function/http://adobe.com/AS3/2006/builtin::apply()
at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleMessage()[/Users/Lapo/Documents/Flex Builder 2/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/handlers/SysHandler.as:84]
at it.gotoandplay.smartfoxserver::SmartFoxClient/xmlReceived()[/Users/Lapo/Documents/Flex Builder 2/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:327]
at it.gotoandplay.smartfoxserver::SmartFoxClient/handleMessage()[/Users/Lapo/Documents/Flex Builder 2/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:1418]
at it.gotoandplay.smartfoxserver::SmartFoxClient/handleSocketData()[/Users/Lapo/Documents/Flex Builder 2/SmartFoxClient_AS3/src/it/gotoandplay/smartfoxserver/SmartFoxClient.as:1401]
... there is no error when user 2 exits room.
So, I have a button that connects user to server, when user is connected and joined the "lobby" room he can join and create rooms, when 2 players joined, game begins.
I am using SFS Basic with AS3, I don't call getRoomList() anywhere and I need to mention that I have another application similar to this that is working without error (same api, same server, similar function flow).
Tried different solutions, but no help...
I don't understand why I get this error on this application and the other one works fine and why do I get this error only when I create the room and I expect to get an error when any user creates room, not only when user 1 creates the room.
Any help or suggestions are greatly appreciated, I'm struggling with this problems for days...
Update: If I create a 3 players room (game room) and the game is not started and I connect 2 players and then they disconnect everything is fine, but if the game starts and then they disconnect I get this error.
I found the problem and I hope I save someone some time with this answer:
The problem was this line:
sfs.getActiveRoom().getUserList().sort(randomize)[0].getName();
I was using this code to generate a random user to be the first to play, but actualy it seems that I was changing the user list array (by sorting it) (sfs.getActiveRoom().getUserList()) and when the user was leaving the room. Boom! Error! Null Object!
So, I changed with this:
var userList:Array = new Array();
userList = userList.concat(sfs.getActiveRoom().getUserList());
var randomUser = userList.sort(randomize)[0].getName();