# Class to manage objects inside a Shared Object

**URL:** <https://forum.kirupa.com/t/class-to-manage-objects-inside-a-shared-object/88363>\
**Category:** open source\
**Created:** [April 28, 2005, 6:00pm UTC](https://forum.kirupa.com/t/class-to-manage-objects-inside-a-shared-object/88363 "2005-04-28T18:00:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.kirupa.com/u/claudio)\
**Post date:** [April 28, 2005, 6:00pm UTC](https://forum.kirupa.com/t/class-to-manage-objects-inside-a-shared-object/88363/1 "2005-04-28T18:00:36Z")

</div>

Something i needed for a recent project.

```auto
_global.SO = function(name) {
	this.name = name;
};
//	Method to create an object in your SO
SO.prototype.createObject = function(obj) {
	var so = SharedObject.getLocal(this.name);
	so.data[obj] = new Object();
	so.flush();
};
//	Method to delete an object in your SO
SO.prototype.deleteObject = function(obj) {
	var so = SharedObject.getLocal(this.name);
	delete so.data[obj];
};
//	Method to display the objects in your SO
SO.prototype.showObjects = function() {
	var so = SharedObject.getLocal(this.name);
	trace("Objects inside "+this.name+":");
	for (var prop in so.data) {
		trace(prop);
	}
};
//	Method to set a property inside an object in your SO
SO.prototype.setObjectProperty = function(obj, prop, value) {
	var so = SharedObject.getLocal(this.name);
	so.data[obj][prop] = value;
	so.flush();
};
//	Method to get a property inside an object in your SO
SO.prototype.getObjectProperty = function(obj, prop) {
	var so = SharedObject.getLocal(this.name);
	return so.data[obj][prop];
};
//	Method to display the properties inside an object in your SO
SO.prototype.showObjectProperties = function(obj) {
	var so = SharedObject.getLocal(this.name);
	trace("Props inside "+obj+":");
	for (var prop in so.data[obj]) {
		trace(prop+" = "+so.data[obj][prop]);
	}
};
//	Method to purge all objects inside an object in your SO
SO.prototype.purgeObjects = function() {
	var so = SharedObject.getLocal(this.name);
	for (var prop in so.data) {
		delete so.data[prop];
	}
};
//
//	Usage: 
//
//	First create an instance of your SO class
so = new SO("Database");

//	Create a new object inside your SO
so.createObject("user1");

//	You can set properties to any object inside your SO
so.setObjectProperty("user1", "adress", "3th street");
so.setObjectProperty("user1", "tel", "555-5555");

//	You get properties for any object inside your SO
trace("user1 adress:"+so.getObjectProperty("user1", "adress"));

//	Print the objects inside your SO
so.showObjects();

//	Check the properties of any object inside your SO
so.showObjectProperties("user1");

//	Purge all objects inside your SO
so.purgeObjects();

```
