| Package | com.electrotank.electroserver4.entities |
| Class | public class RoomVariable |
import com.electrotank.electroserver4.ElectroServer;
import com.electrotank.electroserver4.entities.RoomVariable;
import com.electrotank.electroserver4.esobject.EsObject;
import com.electrotank.electroserver4.message.event.RoomVariableUpdateEvent;
import com.electrotank.electroserver4.message.MessageType;
import com.electrotank.electroserver4.message.request.CreateRoomVariableRequest;
import com.electrotank.electroserver4.room.Room;
//
var es:ElectroServer;//Assume this was created, connection established, and login established already
var myRoom:Room;//A reference to some room you are in.
//
function init():void {
es.addEventListener(MessageType.RoomVariableUpdateEvent, "onRoomVariableUpdateEvent", this);
}
function createRoomVariable():void {
//The value of the variable is an EsObject
var eob:EsObject = new EsObject();
eob.setString("LoopName", "Happy.mp3");
eob.setInteger("Volume", 80);
//
var crr:CreateRoomVariableRequest = new CreateRoomVariableRequest();
crr.setName("MusicInfo");
crr.setValue(eob);
crr.setRoomId(myRoom.getRoomId());
crr.setZoneId(myRoom.getZone().getZoneId());
crr.setLocked(false);
crr.setPersistent(false);
//
es.send(crr);
}
function onRoomVariableUpdateEvent(e:RoomVariableUpdateEvent):void {
//name of the variable affected
var varName:String = e.getName();
//reference to the room that holds the variable
var room:Room = es.getZoneManager().getZoneById(e.getZoneId()).getRoomById(e.getRoomId());
trace("Room variable name: "+varName);
switch (e.getUpdateAction()) {
case RoomVariableUpdateEvent.VariableCreated:
trace("Variable created");
var rv:RoomVariable = room.getRoomVariable(name);
trace("Room variable value: "+rv.getValue());//Will just trace out an object reference of the EsObject;
break;
case RoomVariableUpdateEvent.VariableUpdated:
trace("Variable updated");
var rv:RoomVariable = room.getRoomVariable(name);
trace("Room variable value: "+rv.getValue());//Will just trace out an object reference of the EsObject;
break;
break;
case RoomVariableUpdateEvent.VariableDeleted:
trace("Variable deleted");
break;
default:
trace("Action not handled: "+e.getUpdateAction());
break;
}
}
init();
createRoomVariable();
| Method | Defined by | ||
|---|---|---|---|
|
RoomVariable(tmpname:String, tmpvalue:EsObject, perst:Boolean, lkd:Boolean)
This class is used to represent a room variable.
| RoomVariable | ||
|
getLocked():Boolean
Gets the variable's locked property.
| RoomVariable | ||
|
getName():String
Gets the variable name.
| RoomVariable | ||
|
getPersistent():Boolean
Returns the persistent property of the variable.
| RoomVariable | ||
|
Gets the variable value.
| RoomVariable | ||
|
setLocked(locked:Boolean):void
Sets the locked property of the variable.
| RoomVariable | ||
|
setName(name:String):void
Sets the variable name.
| RoomVariable | ||
|
setPersistent(persistent:Boolean):void
Sets the persistent property of the variable.
| RoomVariable | ||
|
Sets the variable value.
| RoomVariable | ||
| RoomVariable | () | constructor |
public function RoomVariable(tmpname:String, tmpvalue:EsObject, perst:Boolean, lkd:Boolean)This class is used to represent a room variable. It is created internally to the API. Creating an instance of this class yourself isn't common.
Parameterstmpname:String — Name of the variable.
|
|
tmpvalue:EsObject — EsObject value of the variable.
|
|
perst:Boolean — True or false. If true, then the variable will stay around after the user that created it leaves. If false, then the variable will die when the user leaves.
|
|
lkd:Boolean — True or false. If true, then the variable's value cannot be changed until unlocked. It can still be deleted when locked.
|
| getLocked | () | method |
public function getLocked():BooleanGets the variable's locked property.
ReturnsBoolean — True or false.
|
| getName | () | method |
public function getName():StringGets the variable name.
ReturnsString — The variable name.
|
| getPersistent | () | method |
public function getPersistent():BooleanReturns the persistent property of the variable.
ReturnsBoolean — True or false.
|
| getValue | () | method |
| setLocked | () | method |
public function setLocked(locked:Boolean):voidSets the locked property of the variable. If locked is true then the variable's value cannot be updated. If false it can be updated.
Parameterslocked:Boolean — True or false.
|
| setName | () | method |
public function setName(name:String):voidSets the variable name.
Parametersname:String — The variable name.
|
| setPersistent | () | method |
public function setPersistent(persistent:Boolean):voidSets the persistent property of the variable. If persistent is true the variable remains when the user leaves the room, else it is removed.
Parameterspersistent:Boolean — True or false.
|
| setValue | () | method |
public function setValue(value:EsObject):voidSets the variable value.
Parametersvalue:EsObject — The variable value.
|