- A local SharedObject saves information permanently on the local file system (like cookies in a browser).
- However, local SharedObjects can store typed data such as numbers, objects, and functions.
- To create a new local SharedObject, we use the getLocal() method:
player1Info_so = SharedObject.getLocal("player1");
- If "player1" already exists, it is retrieved rather than created.
- We now assign custom properties to the built-in data property:
player1Info_so.data.highScore = 1200;
- The object is saved as an .sol file when:
- the movie is closed
- the flush() method is invoked
- the SharedObject is deleted and garbage collected
- Once saved, the SharedObject can be retrieved later with the getLocal() method, exactly as it was created.
- By default, each domain can store up to 100kb of data on the user's computer.
- An example that tracks the total time a user has spent on a movie.
var userProfile_so = SharedObject.getLocal("userProfile");
trace(userProfile_so.data.totalVisitTime);
var then = 0;
this.onEnterFrame = function () {
var now = getTimer();
var frameTime = now - then;
userProfile_so.data.totalVisitTime += frameTime;
this.then = now;
}