16.4. Saving a Local Shared Object


You want to save local shared object data to the client computer.


Use the SharedObject.flush( ) method in the Flash movie.


Flash automatically attempts to save local shared object data to disk when the movie is unloaded from the Player (such as when the Player closes). However, it is not a good practice to rely on the automatic save functionality, as there are several reasons why the data might not save successfully. Instead, you should explicitly instruct the local shared object to write the data to disk using the SharedObject.flush( ) method:

flushResult = my_l_so.flush(  );

When the flush( ) method is invoked, it attempts to write the data to the client computer. The result of a flush( ) invocation can be one of three possibilities:

  • If the user set the local storage for the domain to “Never”, the data is not saved and the method returns false.

  • If the amount of disk space required to save the local shared object’s data is less than the local storage setting for the domain, the data is written to disk and the method returns true.

  • If the user has not allotted as much space as the shared object data requires, he is prompted to allow enough space or to deny access to save the data. When this happens, the method returns “pending”. If the user chooses to grant access, the extra space is automatically allotted and the data is saved.

In the third case, in which the flush( ) method returns “pending”, there is an additional step you can ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.