Macromedia Flash Server - ServerSide Client Scope

This is Interesting: Free IT Magazines  
Home > Archive > Macromedia Flash Server > May 2005 > ServerSide Client Scope





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author ServerSide Client Scope
Simon Skrřdal

2005-05-04, 2:45 am

I am struggling a little with understanding scope on the serverside, =
and, although I think I have a workaround for a specific problem, I just =
want to run it through with you guys for '(dis)approval'.

My problem is understanding client-specific variables on the serverside =
- what is 'private' to the individual client, and what is not.

For example, I have found that in onConnect(clientObj), I can add stuff =
like: clientObj.firstName =3D someDynamicChangingName;
....and then later, in onDisconnect, I can trace(clientObj.firstName); =
....and get the unique names added in the other function. Am I right so =
far?

Now, in a custom declared SS function, my client passes a variable, =
let's call it 'myVar'. I want this variable to be unique for each =
client, but I no longer have the clientObj reference, so I can't do =
clientObj.var =3D myVar, since clientObj only seems to exist within the =
scope of the connect/disconnect functions.=20

So what I did was to assign myVar to Client, i.e. Client.var =3D myVar;

It looks like that did the trick - if I now trace clientObj.var in =
onDisconnect(); I seem to be getting the value assigned to Client.var, =
but is this really the way I should be doing it? If a hundred clients =
connects, and all passes separate values for myVar, will this still =
work?

Ahw, not sure if I get my question right, but if you understand what I =
mean, any help would be appreciated


Kind regards,
Simon Skr=F8dal

=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------

To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm

Stefan Richter

2005-05-04, 7:45 am

I think you are on the right track, you can indeed save variables into =
the
client object onconnect and then access the same variables inside
onDisconnect.

If you want a SS function that each client can call then do this:

Client.prototype.myfunc =3D function(para){
this.someValue =3D para;=20
/* 'this' is the client which calls the function, so you could also
use it to update the client's username etc, it's the same client object
as inside onConnect */

// once updated you can either do this
return true; // true gets sent to the client who called myfunc - if
he is expecting and // listening for return
value

// or a more obvious way is this
this.call("myfuncDone", null, true);
// the call will trigger a function of the form of
netconn.myfuncDone(para) on the client
}



Let's just recap, initially you can set a username like this:

application.onConnect(newclient, username){ // let's assume that =
username =3D
'Stefan'
newclient.username =3D username; // username property of this client
object is now 'Stefan'
acceptConnection(newclient);=20
}

Later, the same client calls this

Client.prototype.updateUsername =3D function(newname){ // let's assume =
that
newname =3D 'Simon'
this.username =3D newname;=20
// now the username property of the client is 'Simon'
}


HTH

Stefan






> -----Original Message-----
> From: flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org=20
> [mailto:flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org] On Behalf Of=20
> Simon Skr=F8dal
> Sent: 04 May 2005 06:33
> To: FlashComm Mailing List
> Subject: [FlashComm] ServerSide Client Scope
>=20
> I am struggling a little with understanding scope on the=20
> serverside, and, although I think I have a workaround for a=20
> specific problem, I just want to run it through with you guys=20
> for '(dis)approval'.
>=20
> My problem is understanding client-specific variables on the=20
> serverside - what is 'private' to the individual client, and=20
> what is not.
>=20
> For example, I have found that in onConnect(clientObj), I can=20
> add stuff like: clientObj.firstName =3D=20
> someDynamicChangingName; ...and then later, in onDisconnect,=20
> I can trace(clientObj.firstName); ...and get the unique names=20
> added in the other function. Am I right so far?
>=20
> Now, in a custom declared SS function, my client passes a=20
> variable, let's call it 'myVar'. I want this variable to be=20
> unique for each client, but I no longer have the clientObj=20
> reference, so I can't do clientObj.var =3D myVar, since=20
> clientObj only seems to exist within the scope of the=20
> connect/disconnect functions.=20
>=20
> So what I did was to assign myVar to Client, i.e. Client.var =3D =

myVar;
>=20
> It looks like that did the trick - if I now trace=20
> clientObj.var in onDisconnect(); I seem to be getting the=20
> value assigned to Client.var, but is this really the way I=20
> should be doing it? If a hundred clients connects, and all=20
> passes separate values for myVar, will this still work?
>=20
> Ahw, not sure if I get my question right, but if you=20
> understand what I mean, any help would be appreciated
>=20
>=20
> Kind regards,
> Simon Skr=F8dal
>=20
> =3D---------------------------------------------------------
> Supported by Fig Leaf Software - http://www.figleaf.com
> =3D---------------------------------------------------------
>=20
> To change your subscription options or search the archive:
> http://chattyfig.figleaf.com/mailman/listinfo/flashcomm
>=20



=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------

To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm

Frédéric v. Bochmann

2005-05-04, 5:45 pm

I think your right :P


Fredz./

-----Original Message-----
From: flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org
[mailto:flashcomm-bounces-1Ss2GqJETD3yZ38Mhd3e/9ZfFG6BLHNm@public.gmane.org] On Behalf Of Simon =
Skr=F8dal
Sent: May 4, 2005 1:33 AM
To: FlashComm Mailing List
Subject: [FlashComm] ServerSide Client Scope

I am struggling a little with understanding scope on the serverside, =
and,
although I think I have a workaround for a specific problem, I just want =
to
run it through with you guys for '(dis)approval'.

My problem is understanding client-specific variables on the serverside =
-
what is 'private' to the individual client, and what is not.

For example, I have found that in onConnect(clientObj), I can add stuff
like: clientObj.firstName =3D someDynamicChangingName;
....and then later, in onDisconnect, I can trace(clientObj.firstName); =
....and
get the unique names added in the other function. Am I right so far?

Now, in a custom declared SS function, my client passes a variable, =
let's
call it 'myVar'. I want this variable to be unique for each client, but =
I no
longer have the clientObj reference, so I can't do clientObj.var =3D =
myVar,
since clientObj only seems to exist within the scope of the
connect/disconnect functions.=20

So what I did was to assign myVar to Client, i.e. Client.var =3D myVar;

It looks like that did the trick - if I now trace clientObj.var in
onDisconnect(); I seem to be getting the value assigned to Client.var, =
but
is this really the way I should be doing it? If a hundred clients =
connects,
and all passes separate values for myVar, will this still work?

Ahw, not sure if I get my question right, but if you understand what I =
mean,
any help would be appreciated


Kind regards,
Simon Skr=F8dal

=3D---------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=3D---------------------------------------------------------

To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm


=-----------------------------------------------------------
Supported by Fig Leaf Software - http://www.figleaf.com
=-----------------------------------------------------------

To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcomm

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com