This request creates or updates a user variable. A user variable is a name/value pair scoped to a user and store in the server. A user can see his/her own user variables, and can see the
user variables for all people in the same room as them. The value is an EsObject. In addition to creating a user variable with this request, user variables can be created during the
login process (see LoginRequest) or by the server. A user variable is deleted using the DeleteUserVariableRequest.
This shows how to create a user variable and capture the update event.
private var _es:ElectroServer;
private function initialize():void {
_es.engine.addEventListener(MessageType.UserVariableUpdateEvent.name, onUserVariableUpdateEvent);
testCreateUserVariable();
}
private function testCreateUserVariable():void {
//create the request and populate it with info
var uuvr:UpdateUserVariableRequest = new UpdateUserVariableRequest();
uuvr.name = "myDescription";
uuvr.value = new EsObject();
uuvr.value.setString("hairColor", "brown");
uuvr.value.setInteger("age", 35);
//send to the server
_es.engine.send(uuvr);
}
private function onUserVariableUpdateEvent(e:UserVariableUpdateEvent):void {
var userVar:UserVariable;
switch (e.action) {
case UserVariableUpdateAction.VariableCreated:
//the user variable is managed, so grab it
userVar = _es.managerHelper.userManager.me.userVariableByName(e.variable.name);
trace("User variable created. Name: " + userVar.name + ", value: " + userVar.value.toString());
break;
case UserVariableUpdateAction.VariableDeleted:
//the user variable has already been deleted, so to see its name inspect the event object
trace("User variable deleted. Name: " + e.variable.name);
break;
case UserVariableUpdateAction.VariableUpdated:
//the user variable is managed, so grab it
userVar = _es.managerHelper.userManager.me.userVariableByName(e.variable.name);
trace("User variable updated. Name: " + userVar.name + ", value: " + userVar.value.toString());
break;
}
}