The sendObject()

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

Moderators: Lapo, Bax

sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

The sendObject()

Postby sandwichs » 11 Mar 2006, 03:43

I'm trying to use the sendObject
So, from the tutorial I got:

move = new Object()
move.px = 100
move.py = 200
move.color = "red"

sendObject(move)

Then (I supposed on the same frame of the movie) I got

smartfox.onObjectReceived = function(obj, user)
{
// do something here
}

Could anyone tell me what the "do something here" could be??

I also tried a piece of code I found on this forum that look like this:
smartfox.onObjectReceived = function(obj:Object, user:User) BUT then I recieve an error message:
The class 'User' could not be loaded
Joe
Posts: 37
Joined: 21 Aug 2005, 14:25
Location: Paris

Postby Joe » 11 Mar 2006, 12:16

Could anyone tell me what the "do something here" could be??

onObjectReceived is triggered after a flash client has called sendObject(object)
it's generally used to notify another flash client of something he has done

example : you are developing a RPG game, 2 players are fighting the same monster, each time the monster is hurt by one player, the other player (i.e. the other flash client) must be notified of the updated life points total of the monster.

for your error on User class check that teh correct import has been done and that you have correctly installed smartfox flash API, this is explained here
viewtopic.php?t=16

Hope my answer will help ...

Joe
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

Postby sandwichs » 11 Mar 2006, 17:13

not at all but thanks for trying
Joe
Posts: 37
Joined: 21 Aug 2005, 14:25
Location: Paris

Postby Joe » 11 Mar 2006, 22:00

I suggest you to rewrite your post to be understandable ...

peace
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

Postby sandwichs » 11 Mar 2006, 23:14

Regarding the
The class 'User' could not be loaded, it looks like it depends where the smartfox.onObjectReceived = function(obj:Object, user:User) . It works on some frames and not on others.. So I will probably figure it out at some point.

Regarding the
smartfox.onObjectReceived = function(obj, user)
{
// do something here
}
Well.. I don't know what to use to replace the "do something here " with the move.px and move.py values


NOTE:
I would be happy to pay someone to take the game code and transform it into a multi-player game.
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 12 Mar 2006, 16:10

Hello again

First of all. sendObject() is a method of the SmartFoxServer object. So it needs to be called accordingly or else it will fail silently

Code: Select all

move = new Object()
move.px = 100
move.py = 200
move.color = "red"
sendObject(move);// this will do nothing and yeld no error whatsoever
smartfox.sendObject(move); // this will send the object to all players connected in the same room

Supposing that the SFS Client instance is called smartfox and not some other name (including smartFox with a capital F) the move object will arrive to it's destination (all players) and trigger the onObjectRecieved Event. Inside that callback function, SFS will tell you what the object is and with all it's properties, and who is the "user" that sent the object;
As it can be also seen from the examples in the documentation you can access the object like this

Code: Select all

smartfox.onObjectReceived = function(obj, sender)
{
     trace("Got data from: " + sender.getName());
     trace("X = " + obj.px + ", Y = " + obj.py);
     trace("The attached color is "+obj.color)
}


This has to help 8)

Good Luck
Last edited by Virusescu on 12 Mar 2006, 16:16, edited 1 time in total.
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
User avatar
Virusescu
Posts: 260
Joined: 07 Sep 2005, 09:36
Location: [RO]Bucharest
Contact:

Postby Virusescu » 12 Mar 2006, 16:15

Also note that in order for you SFS classes to be accessible in every frame you need to import them before you use them (IN EACH FRAME)

Code: Select all

import it.gotoandplay.smartfoxserver.*;
function onJoin(usr) {if (usr.getName() == "Lapo") trace ("All Hail Lapo");}
sandwichs
Posts: 12
Joined: 26 Feb 2006, 04:08

getting closer

Postby sandwichs » 12 Mar 2006, 22:43

I opened the simple chat example.
Where the chat frame is, I put the following:

move = new Object()
move.px = 100
move.py = 200
move.color = "red"
sendObject(move);// this will do nothing and yeld no error whatsoever
smartfox.sendObject(move); // this will send the object to all players connected in the same room
stop()
smartfox.onObjectReceived = function(obj, sender)
{
trace("Got data from: " + sender.getName());
trace("X = " + obj.px + ", Y = " + obj.py);
trace("The attached color is "+obj.color)
chat_txt="X = " + obj.px + ", Y = " + obj.py
}

I can see that it's sending but it doesn't trace the receive(Not sure it's normal because I read that the sender doesn't receive, but I opened it twice and I still don't see it).
When I look at the DOS prompt where the server is running, it says:
Problens parsing source room ID for Action: asObj >java.lang.NumberFormatExecption: For input string : "null"
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 13 Mar 2006, 06:28

When I look at the DOS prompt where the server is running, it says:
Problens parsing source room ID for Action: asObj >java.lang.NumberFormatExecption: For input string : "null"


This is because you're not yet logged in a room.
It's important to understand that a user must be inside at least one room before he/she can interact with the server.

Please check this article > http://www.smartfoxserver.com/docs/docP ... pTemplate/

One more thing: I'd suggest to take your time with all the examples contained in our docs. Creating multiplayer games is not difficult once you understand the basic concepts, but it takes some time to get used to this "new world".
If you follow the examples in the order they are presented, you will understand and learn new concepts gradually and start seeing how to build your own game.

Hope it helps :)
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 53 guests