getAllUsers() is reporting an error...

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

getAllUsers() is reporting an error...

Post 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]
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Post 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
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Post 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]
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Post 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.
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Post 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.
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Post 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.
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Post by patso »

try this:

Code: Select all

usersInRoom = _server.getCurrentZone().getRoom(fromRoom).getAllUsers();
poppop
Posts: 57
Joined: 07 Jul 2007, 10:24

Post by poppop »

Thanks for all the help guys!!! :lol:

patso -- your code worked perfect, thanks so much! :idea:
Post Reply