SFS Variables

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Sevil
Posts: 15
Joined: 29 May 2015, 20:38

SFS Variables

Postby Sevil » 03 Jun 2015, 18:44

Very strange behavior with setting variables, right example:
first I made as described in Example:

Code: Select all

sVars.push(new SFSRoomVariable("variable1", "1"));
sVars.push(new SFSRoomVariable("variable2", "2"));
sVars.push(new SFSRoomVariable("variable3", "3"));
sfs.send( new SetRoomVariablesRequest(sVars));
...
...
private function onRoomVarsUpdate(evt:SFSEvent):void
{
     trace("onRoomVarsUpdate");
}

and no response

but if to do so:

Code: Select all

sVars.push(new SFSRoomVariable("variable1", "1"));
sVars.push(new SFSRoomVariable("variable2", "2"));
sVars.push(new SFSRoomVariable("variable3", "3"));
sfs.send( new SetUserVariablesRequest(sVars));
...
...
private function onUserVarsUpdate(evt:SFSEvent):void
{
     trace("onUserVarsUpdate");
}

then the answer is, and variables are displayed on the server on user

Is that the way it should be?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS Variables

Postby Lapo » 04 Jun 2015, 08:10

Hi,
please check your server side logs / console to see if there's an error after setting the RoomVariables.

Also, RoomVariables require the User to be joined in the Room to create them.

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
Sevil
Posts: 15
Joined: 29 May 2015, 20:38

Re: SFS Variables

Postby Sevil » 04 Jun 2015, 21:27

No errors were observed. But another question, why creating variables of type SFSRoomVariable they are transmitted by
sfs.send( new SetUserVariablesRequest());

but if do type variables SFSUserVariable, this method they did not react and
private function onUserVarsUpdate(evt:SFSEvent):void
{
}
do not cause.

First I did the example:

Code: Select all

sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, onUserVarsUpdate);

var sVars:Array = [];
...
sVars.push(new SFSUserVariable("p1", p1.text));
sVars.push(new SFSUserVariable("p2", p2.text));
sVars.push(new SFSUserVariable("p3", p3.text));
sfs.send(new SetUserVariablesRequest(sVars));
...
private function onUserVarsUpdate(evt:SFSEvent):void
{
   trace("onUserVarsUpdate");
}

and 0 react. "onUserVarsUpdate" not activated.
but when I change the type of variables created:

Code: Select all

sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, onUserVarsUpdate);

var sVars:Array = [];
...
sVars.push(new SFSRoomVariable("p1", p1.text));
sVars.push(new SFSRoomVariable("p2", p2.text));
sVars.push(new SFSRoomVariable("p3", p3.text));
sfs.send(new SetUserVariablesRequest(sVars));
...
private function onUserVarsUpdate(evt:SFSEvent):void
{
   trace("onUserVarsUpdate");
}

me showed "onUserVarsUpdate"...

Is not that strange behavior?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS Variables

Postby Lapo » 05 Jun 2015, 07:19

No, it's not a strange behavior but you must not mix types.
If you're sending a SetRooVariableRequest you should pass an array of SFSRoomVariables and viceversa.

The fact that the compiler doesn't complain is simply because the RoomVariable class extends UserVariable so, technically, it is acceptable.

Back to your problem, I don't have enough information. From your code snippets nothing seems wrong, but there's a lot of missing data. We provide many examples with source code where Room Variables and User Variables are used. It would probably be best if you took a look at them.

See here:
http://docs2x.smartfoxserver.com/Exampl ... vatar-chat
http://docs2x.smartfoxserver.com/ExamplesFlash/tris
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 14 guests