Page 1 of 1
getAllUsers() is reporting an error...
Posted: 22 Aug 2007, 21:11
by poppop
Hello.
I'm trying to send a response to all users in a room, but when i try the code below (the code is server side):
Code: Select all
var usersArray = _server.getCurrentRoom().getAllUsers();
room = _server.getCurrentRoom()
usersInRoom = room.getAllUsers()
_server.sendResponse(response, -1, null, usersInRoom);
I'm getting this error on the server:
Code: Select all
2007/08/22 22:35:47.843 - [ WARNING ] [id: 11] (JavascriptExtension.logASError): Error in extension [ myExt.as ]:
Please help.
Thanks.[/quote]
Posted: 23 Aug 2007, 06:45
by Lapo
Try running this code:
Code: Select all
var room = _server.getCurrentRoom()
trace("room: " + room)
usersInRoom = room.getAllUsers()
trace("users: " + usersInRoom)
and tell us what it outputs
thanks
Posted: 23 Aug 2007, 09:39
by poppop
Thanks Lapo,
I get the same error:
Code: Select all
2007/08/23 11:05:19.921 - [ WARNING ] [id: 11] (JavascriptExtension.logASError): Error in extension [ myExt.as ]: TypeError: Cannot call method "getAllUsers" of null (myExt.as#1421) Internal: 91 -- Line number: 91 in file: myExt.as
Posted: 23 Aug 2007, 09:51
by Lapo
mmm...
it seems that the error is clearer now.
You should check line 91 of myExt.as and look for a null object, where you're probably expecting a Room object
Posted: 23 Aug 2007, 16:00
by poppop
line 91 is this:
var room = _server.getCurrentRoom()
trace("room: " + room)
usersInRoom = room.getAllUsers()
trace("users: " + usersInRoom)
_server.sendResponse(response, -1, null, usersInRoom);
The output of this trace on line 90:
trace("room: " + room)
is:
"room: null"
I'm calling the handleRequest function on the server from the client side:
smartfox.onJoinRoom = function(roomObj:Room) function
I do not know what's going wrong?
Any more help would be really great. Thanks.
[/code]
Posted: 23 Aug 2007, 16:16
by poppop
All i really want to do, is send a server response to all users in the current room? using actionscript, server side
Thanks again.
Posted: 23 Aug 2007, 16:26
by patso
If the extension is zone level the _server.getCurrentRoom() always return null so when you call room.getAllUsers() you get this error.
Not 100% sure but I think this is the problem.
Posted: 23 Aug 2007, 16:54
by poppop
patso -- You are right, this is a zone level extension.
How can i use the fromRoom object to get the users in that roon then?
Code: Select all
function handleRequest(cmd, params, user, fromRoom) {
fromRoom.getAllUsers();
Somthing like that would be great.
Cheers.
Posted: 24 Aug 2007, 06:25
by patso
try this:
Code: Select all
usersInRoom = _server.getCurrentZone().getRoom(fromRoom).getAllUsers();
Posted: 24 Aug 2007, 10:00
by poppop
Thanks for all the help guys!!!
patso -- your code worked perfect, thanks so much!
