...ok and getting user variables?
...ok and getting user variables?
Not seeming to have much luck here..
reading the API I see a function "getVariable" and "getVariables" but Flex keeps telling me those methods don't exist and upon opening the actionscript files for SmartFoxClient ... I can't seem to to find those methods either.
also I added an event listener to listen for user variable updates ... then in the function that gets called i just put in trace("updated") ... so while debugging I don't see that "updated" appear in the console, but I see lines (on every frame because that's how/when I'm updating my user variables with an enter frame even listener) -- anyway i see the lines saying "[Sending]: <msg t= ....." blah blah blah . and under the admin tool i can refresh and see updatinng variables. cool!
but i can't seem to now access those variables... not through an event listener for when those variables are being updated/stored and not by using the method "getVariable" or "getVariables"
i think everything has been fairly straight forward here and again I love SFS, but is it possible that the AS3 API isn't complete? do i have an old version maybe? i downloaded the one for Flash CS3 (and am using the one for Flex...the swc)
reading the API I see a function "getVariable" and "getVariables" but Flex keeps telling me those methods don't exist and upon opening the actionscript files for SmartFoxClient ... I can't seem to to find those methods either.
also I added an event listener to listen for user variable updates ... then in the function that gets called i just put in trace("updated") ... so while debugging I don't see that "updated" appear in the console, but I see lines (on every frame because that's how/when I'm updating my user variables with an enter frame even listener) -- anyway i see the lines saying "[Sending]: <msg t= ....." blah blah blah . and under the admin tool i can refresh and see updatinng variables. cool!
but i can't seem to now access those variables... not through an event listener for when those variables are being updated/stored and not by using the method "getVariable" or "getVariables"
i think everything has been fairly straight forward here and again I love SFS, but is it possible that the AS3 API isn't complete? do i have an old version maybe? i downloaded the one for Flash CS3 (and am using the one for Flex...the swc)
ok well i realized i was accessing the wrong class =0
but still ... i can't return variables ... just got the errors to all go away.
i CAN get my user name etc. through the user class but no variables.
yet the admin tool shows variables..
(also the console shows the "[Sending]" AND "[RECEIVED]" info -- so it's going there and updating, etc. even calls the event handler -- but i still can't figure out how to get the data, tracing something like: sfsUser.getVariables() doesn't seem to work)
but still ... i can't return variables ... just got the errors to all go away.
i CAN get my user name etc. through the user class but no variables.
yet the admin tool shows variables..
(also the console shows the "[Sending]" AND "[RECEIVED]" info -- so it's going there and updating, etc. even calls the event handler -- but i still can't figure out how to get the data, tracing something like: sfsUser.getVariables() doesn't seem to work)
[ RECEIVED ]: <msg t='sys'><body action='uVarsUpdate' r='10'><user id='140' /><vars><var n='myAvatar' t='s'><![CDATA[Tom]]></var><var n='posy' t='n'><![CDATA[298.16160615194735]]></var><var n='posx' t='n'><![CDATA[124.38240634389908]]></var></vars></body></msg>, (len: 247)
something updated
that's from my console ... no fair my console can read the data but i can't =(
lol
and "something updated" is from trace("something updated"); that I put in the listener for when user variables update...
i've instantiated a user object... called it sfsUser
so sfsUser.getVariables()
right?
trace(sfsUser.getVariables());
nothing
var theVars = sfsUser.getVariables();
trace(theVars);
nothing
i'm a noob I know. lol
something updated
that's from my console ... no fair my console can read the data but i can't =(
lol
and "something updated" is from trace("something updated"); that I put in the listener for when user variables update...
i've instantiated a user object... called it sfsUser
so sfsUser.getVariables()
right?
trace(sfsUser.getVariables());
nothing
var theVars = sfsUser.getVariables();
trace(theVars);
nothing
i'm a noob I know. lol
i've tried both:
sfsUser = new User(sfs.myUserId, sfs.myUserName);
(in hopes to retrieve the user's own variables which i guess is silly because if you're setting them to begin with you know what they are)
and so i also tried
sfsUser = new User(173, "Tom");
(manually setting it to the other player which I guess ultimately I can get from a user list, but I set it to manually test)
then I'll run
sfsUser.getVariables() ... hoping to return the variables for user 173...
but doesn't return anything. yet i see the variables updating in the admin tool for user 173...
how do you run getVariables without setting up a new user object?
sfsUser = new User(sfs.myUserId, sfs.myUserName);
(in hopes to retrieve the user's own variables which i guess is silly because if you're setting them to begin with you know what they are)
and so i also tried
sfsUser = new User(173, "Tom");
(manually setting it to the other player which I guess ultimately I can get from a user list, but I set it to manually test)
then I'll run
sfsUser.getVariables() ... hoping to return the variables for user 173...
but doesn't return anything. yet i see the variables updating in the admin tool for user 173...
how do you run getVariables without setting up a new user object?
Tom, you can't create a new user!
You should do something like this:
where 3 is the user id, and "room" is the Room object in which user 3 is inside. The room object is passed by a number of events, or you can retrieve it like this (for example):
And, btw, you can't retrive the variables of your own user, as you should already know them when you set them).
You should do something like this:
Code: Select all
sfsUser = room.getUser(3)Code: Select all
sfs.getActiveRoom()Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
thanks for all your help.
still confused but i'll give it a go here real quick.
that didn't seem to return al ist of variables... there is a user id 1 when i look in the admin tool...
still confused but i'll give it a go here real quick.
Code: Select all
var room:Object = sfs.getActiveRoom();
sfsUser = room.getUser(1) ;
var userVars:Array = sfsUser.getVariables();
trace(userVars);
Last edited by Tom on 04 Jun 2007, 17:31, edited 1 time in total.
Sorry, it seems I haven't been clear... after you get an existing user (see my previous post), then you can retrieve his variables using the methods .getVariable or .getVariablesTom wrote:so you never have to use the method getVariables?
when does that come into play?
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
This should be the working code:
Also, are you sure that user 1 has some variables set?
Code: Select all
var room:Room = sfs.getActiveRoom();
var sfsUser:User = room.getUser(1);
var userVars:Object = sfsUser.getVariables();
for (var k:String in userVars)
trace(k + " -> " + userVars[k]);Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
ah groovy it works! thank you sooo much you have no idea how hard i was banging my head over this.
thank you VERY MUCH for your time.
i knew it was probably something simple. just a few lines of code, but i couldn't find many examples in the documentation... they were a bit more complex than what i was after. i was just after a very specific (maybe limited) thing.
thanks again.
thank you VERY MUCH for your time.
i knew it was probably something simple. just a few lines of code, but i couldn't find many examples in the documentation... they were a bit more complex than what i was after. i was just after a very specific (maybe limited) thing.
thanks again.