Use SharedObject to Save Local Data

Shared objects are quite powerful: they offer real-time data sharing between objects that are persistent on the local location. You can think of local shared objects as "cookies."



Description:
SharedObject can be taken as a small database, we use it to store any data type supported by Flash, such as, number, character string, array, object, etc. ShareObject can be divided into local (exist client-side) and long-distance (exist serve side). Extension of local shared object is .sol. For windows2000 (xp), the default storage path is “Application Data\Macromedia\Flash Player\Server domain name path\Flash movie name”; for Windows98 (xp), the default storage path is “Documents and Settings\[User]\Application Data\Macromedia\Flash Player\ Server domain name path\Flash movie name.

Method summary for the SharedObject object
1. SharedObject.getLocal: Returns a reference to a locally persistent shared object that is available only to the current client.
2. SharedObject.flush: Immediately writes a locally persistent shared object to a local file.
3. SharedObject.data: The collection of attributes assigned to the data property of the object, which will be shared and/or stored.
If you get the above knowledge, you can use shared object to store external data now.

Example:

Code:
//For instance, some variables such as weapon, up, down, left, right, jump, atk in SWF game;
//Use following sentences to write to local data;
var so:SharedObject = SharedObject.getLocal("keyset");
so.data.sword = weapon;
so.data.up = up;
so.data.down = down;
so.data.left = left;
so.data.right = right;
so.data.jump = jump;
so.data.atk = atk;
so.flush();//Immediately write data, If this method is not called, Player can also call them automatically when it shuts down.
//=======================
//Use the following sentences to read local data.
var so:SharedObject = SharedObject.getLocal("keyset");
weapon = so.data.sword;
up = so.data.up;
down = so.data.down;
left = so.data.left;
right = so.data.right;
jump = so.data.jump;
atk = so.data.atk;


 

Local shared object can only storage data in default path, and extension can only be .sol.

Hope you are on the right track!  Thanks for sharing time with me~

Back to Top >>

Home

Sothink is a trademark of SourceTec Software Co., LTD.
Flash is a trademark of Adobe.
Sothink Software: Flash to HTML5 Logo Maker

1234