O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

16.10. Adding Data to a Server-Side Shared Object

Problem

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

Solution

Use the SharedObject.setProperty( ) method.

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);

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required