16.7. Saving Remote Shared Object Data

Problem

You want to save the data stored in a remote shared object.

Solution

Define an onAppStop( ) callback handler or use the SharedObject.flush( ) method on the server.

Discussion

When you are working with RSOs, there are really two shared objects: the object as it exists on the server and the object as it exists on the client. And in a scenario in which the shared objects are persistent, there is both a persistent, disk-based version and a working version stored in memory. As the client makes changes to the data in the client-side, memory-based shared object, it is automatically sent to the server, and the data in the server-side, memory-based shared object is synchronized with the client-side data. And once the server data is updated, the onSync( ) method is invoked for all clients connected to the RSO.

// Create or open an RSO and connect to it.
my_r_so = SharedObject.getRemote("myFirstRSO", myConnection.uri);
my_r_so.connect(myConnection);

// Add data to the RSO. The data is automatically sent to the server.
my_r_so.data.myData = "Your Value Here.";

However, even though the memory-based shared objects are kept in synch with one another, the persistent, disk-based shared objects are not always kept in synch with the current data. This is because file access is a relatively “expensive” task. It requires more time to read and write to disk than to read and write to memory. As such, the default behavior for shared objects is that the data is ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.