Recipe 16.10 Adding Data to a Server-Side Shared Object

16.10.1 Problem

You want to add values to a server-side shared object.

16.10.2 Solution

Use the SharedObject.setProperty( ) method.

16.10.3 Discussion

If you try to add values to a server-side shared object in the same way that you add values to a client-side shared object, you will receive an error. The correct way to add values (or modify existing values) to a server-side shared object is to use the SharedObject.setProperty( ) method. The setProperty( ) method requires that you specify both the name of the property and the value to assign to the property.

// This example code should appear in an .asc file. It adds a property named
// myProperty to a shared object and assigns the property the value of 6.
my_r_so.setProperty("myProperty", 6);

If you want to modify an existing property relative to its current value, you can use the getProperty( ) method in conjunction with setProperty( ):

// Set the myProperty property to one more than its current value.
my_r_so.setProperty("myProperty", my_r_so.getProperty("myProperty") + 1);

16.10.4 See Also

See Recipe 16.9 for details on SharedObject.getProperty( ). See Recipe 16.2 for important differences when setting data for a local shared object.

    Part I: Local Recipes
    Part II: Remote Recipes