Package | com.whirled.net |
Interface | public interface PropertySubControl extends PropertyGetSubControl, flash.events.IEventDispatcher |
Implementors | NetSubControl, OfflinePlayerPropertyControl |
Method | Defined by | ||
---|---|---|---|
Execute the specified function as a batch of commands that will be sent to the server
together.
| PropertySubControl | ||
![]() |
get(propName:String):Object
Get a property value.
| PropertyGetSubControl | |
![]() |
getPropertyNames(prefix:String = ""):Array
Get the names of all currently-set properties that begin with the specified prefix.
| PropertyGetSubControl | |
![]() |
getTargetId():int
Get the targetId on which this control operates.
| PropertyGetSubControl | |
set(propName:String, value:Object, immediate:Boolean = false):void
Set a property value to be distributed to the other clients in this game.
| PropertySubControl | ||
setAt(propName:String, index:int, value:Object, immediate:Boolean = false):void
Update one element of an Array.
Note: Unlike setIn(), this update will fail silently if the index is out of bounds or if there is no array currently set at the specified property name. | PropertySubControl | ||
setIn(propName:String, key:int, value:Object, immediate:Boolean = false):void
Update one element of a Dictionary.
Note: Unlike setAt(), this will usually work. | PropertySubControl |
doBatch | () | method |
public function doBatch(fn:Function, ... args):void
Execute the specified function as a batch of commands that will be sent to the server together. Messages can be sent no faster than a rate of 10 per second. Using doBatch groups a number of set or sendMessage operations so that they are treated as a single unit towards this limit. For best performance, it should be used whenever a number of values are being set at once.
Parametersfn:Function |
|
... args |
set | () | method |
public function set(propName:String, value:Object, immediate:Boolean = false):void
Set a property value to be distributed to the other clients in this game. Property values can be any of the primitive types: int, uint, Number, Boolean, String, ByteArray; or you may set Arrays, Dictionarys, or plain old Objects, as long as the values within them are primitive types or other Arrays, Dictionarys and Objects.
You may not set your own classes as properties. However, you can serialize your data into a ByteArray and set that.
Note: top-level Dictionarys must have int keys, the intention is to use occupantIds as keys.
Note that if you set the value as an Array or Dictionary, the value is serialized slightly differently in order to enable updating individual elements efficiently. The individual elements will be serialized separately. You may update the elements individually by using either setAt (for Arrays) or setIn (for Dictionarys). The effect of serializing elements individually is that references to the same object will not be reconstructed off the network as references to the same object. See the example below.
ParameterspropName:String — the name of the property to set.
|
|
value:Object — the value to set. Passing null clears the property.
|
|
immediate:Boolean (default = false ) — if true, the value is updated immediately in the local object. Otherwise
any old value will remain in effect until the PropertyChangedEvent arrives after
a round-trip to the server.
|
See also
// demonstrates expert-level difference between setting values in an array and an object. var o :Object = { blue: true }; var objTest :Object = { 0: o, 1: o}; var arrayTest :Array = [ o, o ]; _ctrl.net.set("object", objTest); _ctrl.net.set("array", arrayTest); // Later, when reading those values back out: var obj :Object = _ctrl.net.get("object"); var array :Array = _ctrl.net.get("array") as Array; trace("array: " + (array[0] == array[1])); // traces false trace("object: " + (obj[0] == obj[1])); // traces true
// demonstrates potentially surprising results when immediate=true _ctrl.set("myProp", 1, true); _ctrl.set("myProp", 2, true); // Some time later, a PropertyChangedEvent will come back from the server, changing // "myProp" back to 1 very briefly, before the second PropertyChangedEvent occurs // and sets it to 2 again. _ctrl.set("myProp", int(_ctrl.get("myProp")) + 1, true); // If the above line is executed after the first PropertyChangedEvent arrives, but // before the second, myProp's final value will be 2. If it's executed after the second // event arrives, myProps final value will be 3. trace(_ctrl.get("myProp")); // might trace "2", might trace "3"
setAt | () | method |
public function setAt(propName:String, index:int, value:Object, immediate:Boolean = false):void
Update one element of an Array.
Note: Unlike setIn(), this update will fail silently if the index is out of
bounds or if there is no array currently set at the specified property name.
Furthermore, if you set the element with immediate=true, there are two updates:
one locally that happens right away and the update on the server that will be
dispatched back to all the clients. Either or both can fail, so be sure to set the Array up
first using set().
propName:String — the name of the property to modify.
|
|
index:int — the array index of the element to update.
|
|
value:Object — the value to set.
|
|
immediate:Boolean (default = false ) — if true, the value is updated immediately in the local object. Otherwise
any old value will remain in effect until the ElementChangedEvent arrives after
a round-trip to the server.
|
See also
setIn | () | method |
public function setIn(propName:String, key:int, value:Object, immediate:Boolean = false):void
Update one element of a Dictionary.
Note: Unlike setAt(), this will usually work. No key is out of range, obviously,
and if you set a value in a property that was previously null, a new Dictionary will
be created to hold your value. If a non-Dictionary property is already stored with the
specified name then this will fail silently on the server. But: don't do that!
It would be pretty bad style to store two different types of property under the same name.
propName:String — the name of the property to modify.
|
|
key:int — the key of the element to update.
|
|
value:Object — the value to set. Passing null removes the specified key from the Dictionary.
|
|
immediate:Boolean (default = false ) — if true, the value is updated immediately in the local object. Otherwise
any old value will remain in effect until the ElementChangedEvent arrives after
a round-trip to the server.
|