| Package | com.adobe.rtc.sharedModel |
| Class | public class SharedObject |
| Inheritance | SharedObject flash.events.EventDispatcher |
| Implements | ISessionSubscriber |
A SharedObject can be used in situations where you need to access a property using its key value as opposed to
index. Similar to SharedCollection and SharedProperty,this component supports "piggybacking" on existing CollectionNodes,
through its collectionNode property and its subscribe method. Developers can avoid CollectionNode
proliferation in their applications by pre-supplying a CollectionNode (to the collectionNode property)
and a nodeName (in the subscribe method) for the SharedObject to use. If none is supplied, the SharedObject will create its own
collectionNode (named for the uniqueID supplied in subscribe()) for sending and receiving messages.
protected var _collectionNode:CollectionNode;
protected var _sharedObject:com.adobe.rtc.sharedModel.SharedObject;
protected function initializeSharedObject():void
{
_collectionNode=new CollectionNode();
_collectionNode.connectSession="YOUR APPS CONNECT SESSION";
_collectionNode.sharedID="tmpCollectionNode";
_sharedObject=new com.adobe.rtc.sharedModel.SharedObject();
_sharedObject.collectionNode=_collectionNode;
_sharedObject.connectSession=sess;
_sharedObject.nodeName="sharedHash";
_sharedObject.sharedID="tmpCollectionNode";
//Subscribe to your collection nodes that does the magic :)
_collectionNode.subscribe();
_sharedObject.subscribe();
_sharedObject.addEventListener(CollectionNodeEvent.SYNCHRONIZATION_CHANGE, onSharedObjSync);
_sharedObject.addEventListener(SharedObjectEvent.PROPERTY_REMOVE,onSharedObjChange);
_sharedObject.addEventListener(SharedObjectEvent.PROPERTY_ADD,onSharedObjChange);
_sharedObject.addEventListener(SharedObjectEvent.PROPERTY_CHANGE,onSharedObjChange);
}
protected function onSharedObjSync(p_evt:CollectionNodeEvent):void
{
if (_sharedObject.isSynchronized) {
_sharedObject.setProperty("key1", "demo1");
_sharedObject.setProperty("key2", 2);
// Modifying the property "key1"
_sharedObject.setProperty("key1", "key1 Mutated");
// Removing the demo1 property from SharedObject
_sharedObject.removeProperty("key2");
// Removing all the properties from the SharedObject
_sharedObject.removeAll();
}
}
protected function onSharedObjChange(p_evt:SharedObjectEvent):void
{
if (_sharedObject.isSynchronized) {
var key:String = p_evt.propertyName;
// Example of SharedObject.getProperty
// Check if the SharedObject is empty
}
}See also
| Property | Defined by | ||
|---|---|---|---|
| collectionNode : CollectionNode
Specifies an existing collectionNode to use in case a developer wishes to supply their own, and avoid having the
sharedObject create a new one.
| SharedObject | ||
| connectSession : IConnectSession
The IConnectSession with which this component is associated.
| SharedObject | ||
| isSynchronized : Boolean [read-only]
Returns whether or not the SharedObject has retrieved any information previously stored on the service, and
is currently connected to the service.
| SharedObject | ||
| nodeName : String
Sets the Node name for the node being created
| SharedObject | ||
| sharedID : String
Defines the logical location of the component on the service - typically this assigns the sharedID of the collectionNode
used by the component.
| SharedObject | ||
| values : Object [read-only]
Return all the items in the shared object as one big hashMap (Object)
| SharedObject | ||
| Method | Defined by | ||
|---|---|---|---|
|
The SharedObject constructor
| SharedObject | ||
|
close():void
Disposes all listeners to the network and framework classes.
| SharedObject | ||
|
getProperty(p_propertyName:String):*
Returns the value of the given property name
| SharedObject | ||
|
getUserRole(p_userID:String):int
Returns the role of a given user for the SharedObject.
| SharedObject | ||
|
hasProperty(p_propertyName:String):Boolean
Returns whether the given property exists or not in the shared object
| SharedObject | ||
|
isEmpty():Boolean
Check if the shared object is empty
| SharedObject | ||
|
removeAll():void
Remove all the items in the shared object.
| SharedObject | ||
|
removeProperty(p_propertyName:String):void
Remove the property from the shared object
| SharedObject | ||
|
setNodeConfiguration(p_nodeConfig:NodeConfiguration):void
Sets the Node Configuration on a already defined node that holds the sharedObject
| SharedObject | ||
|
setProperty(p_propertyName:String, p_value:Object = null):void
Add or Update the value of a given property name in a shared object
| SharedObject | ||
|
setUserRole(p_userID:String, p_userRole:int):void
Sets the role of a given user for the SharedObject.
| SharedObject | ||
|
subscribe():void
Tells the component to begin synchronizing with the service.
| SharedObject | ||
| Event | Summary | Defined by | ||
|---|---|---|---|---|
| Dispatched when an item to SharedObject is added. | SharedObject | |||
| Dispatched when the SharedObject has been updated in some way. | SharedObject | |||
| Dispatched when an item from SharedObject is removed. | SharedObject | |||
| The type of event emitted when the CollectionNode is about to reconnect to the server. | SharedObject | |||
| Dispatched when the SharedObject goes in and out of sync with the service. | SharedObject | |||
| collectionNode | property |
collectionNode:CollectionNode [read-write]Specifies an existing collectionNode to use in case a developer wishes to supply their own, and avoid having the sharedObject create a new one.
Implementation public function get collectionNode():CollectionNode
public function set collectionNode(value:CollectionNode):void
| connectSession | property |
connectSession:IConnectSession [read-write]
The IConnectSession with which this component is associated. Note that this may only be set once before subscribe
is called; re-sessioning of components is not supported. Defaults to the first IConnectSession created in the application.
public function get connectSession():IConnectSession
public function set connectSession(value:IConnectSession):void
| isSynchronized | property |
isSynchronized:Boolean [read-only]Returns whether or not the SharedObject has retrieved any information previously stored on the service, and is currently connected to the service.
This property can be used as the source for data binding.
Implementation public function get isSynchronized():Boolean
| nodeName | property |
nodeName:String [read-write]Sets the Node name for the node being created
Implementation public function get nodeName():String
public function set nodeName(value:String):void
| sharedID | property |
sharedID:String [read-write]
Defines the logical location of the component on the service - typically this assigns the sharedID of the collectionNode
used by the component. sharedIDs should be unique within a room (if they're expressing 2 unique locations). Note that
this can only be assigned once (before subscribe() is called). For components with an id property,
sharedID defaults to that value.
public function get sharedID():String
public function set sharedID(value:String):void
| values | property |
values:Object [read-only]Return all the items in the shared object as one big hashMap (Object)
Implementation public function get values():Object
| SharedObject | () | constructor |
public function SharedObject()The SharedObject constructor
| close | () | method |
public function close():voidDisposes all listeners to the network and framework classes. Recommended for proper garbage collection of the component.
| getProperty | () | method |
public function getProperty(p_propertyName:String):*Returns the value of the given property name
Parametersp_propertyName:String — The key of the Property whose value is requested.
|
* |
| getUserRole | () | method |
public function getUserRole(p_userID:String):intReturns the role of a given user for the SharedObject.
Parametersp_userID:String — The user ID for the user being queried.
|
int |
| hasProperty | () | method |
public function hasProperty(p_propertyName:String):BooleanReturns whether the given property exists or not in the shared object
Parametersp_propertyName:String — The key of the Property whose presence is verified
|
Boolean |
| isEmpty | () | method |
public function isEmpty():BooleanCheck if the shared object is empty
ReturnsBoolean |
| removeAll | () | method |
public function removeAll():voidRemove all the items in the shared object.
| removeProperty | () | method |
public function removeProperty(p_propertyName:String):voidRemove the property from the shared object
Parametersp_propertyName:String — The key of the Property that needs to be retracted from the sharedObject
|
| setNodeConfiguration | () | method |
public function setNodeConfiguration(p_nodeConfig:NodeConfiguration):voidSets the Node Configuration on a already defined node that holds the sharedObject
Parametersp_nodeConfig:NodeConfiguration — The Node Configuration
|
| setProperty | () | method |
public function setProperty(p_propertyName:String, p_value:Object = null):voidAdd or Update the value of a given property name in a shared object
Parametersp_propertyName:String — The key of the Property being added
|
|
p_value:Object (default = null) — The value of the property, defaults to null
|
| setUserRole | () | method |
public function setUserRole(p_userID:String, p_userRole:int):voidSets the role of a given user for the SharedObject.
Parametersp_userID:String — The role value to set on the specified user.
|
|
p_userRole:int — The ID of the user whose role should be set.
|
| subscribe | () | method |
public function subscribe():voidTells the component to begin synchronizing with the service. For "headless" components such as this one, this method must be called explicitly.
| propertyAdd | event |
com.adobe.rtc.events.SharedObjectEvent
Dispatched when an item to SharedObject is added.
| propertyChange | event |
com.adobe.rtc.events.SharedObjectEvent
Dispatched when the SharedObject has been updated in some way.
| propertyRetracted | event |
com.adobe.rtc.events.SharedObjectEvent
Dispatched when an item from SharedObject is removed.
| reconnect | event |
com.adobe.rtc.events.CollectionNodeEvent
The type of event emitted when the CollectionNode is about to reconnect to the server. This typically happens automatically if the SharedObject is still subscribed. The typical response to this event is to re-initialize any shared parts of a model from scratch since they are about to be re-received from the server.
| synchronizationChange | event |
com.adobe.rtc.events.CollectionNodeEvent
Dispatched when the SharedObject goes in and out of sync with the service.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/labs/acrobatcom/com/adobe/rtc/sharedModel/SharedObject.html