Introduction to Local Shared Objects
A local shared object is roughly the flash equivalent of a cookie. However it can do much more than a cookie because it can be used to store relatively large amounts of data clientside. The actual amount of data you can store may vary user to user and their flash player settings but the default limit is 100kb.
Example
If you drag the blue square to a new position and refresh the page, or visit the same movie on another page the square will not reset to the default position (like it normally would) but will appear to stay where you left it.
The way that this works is the x and y values of the square are saved on your computer everytime the square is dragged to a location. Then when the movie loads the position of the square is set via the localobject data which was saved earlier.
Download Source FilesActionscript
squarepos_so = SharedObject.getLocal("positions");
square_mc._x = squarepos_so.data.x;
square_mc._y = squarepos_so.data.y;
square_mc.onPress = function () {
square_mc.startDrag(false,7,26,180,163)
}
square_mc.onRelease = square_mc.onReleaseOutside = function(){
square_mc.stopDrag();
squarepos_so.data.x = square_mc._x;
squarepos_so.data.y = square_mc._y;
squarepos_so.flush();
}
Square_mc is the instance name of the blue square.
squarepos_so = SharedObject.getLocal ("positions"); Get a local shared object called positions, and assigns it to the variable squarepos_so, so it can be easily accessed
Anything that you want to store in the shared object must be assigned to a variable of the data property. In this example the variables are x and y, they are assigned using squarpos_so.data.x= square_mc._y.
squarepos_so.flush(); saves the data from the object to a local file on the users computer.
To start off the movie sets up a localshared object and trys to access the x and y positions of the movielcip. Once the movie is dragged to the new location the new data.x and data.y values set and then written to the local file using the flush() function.
Extension
This was just a very simple example, practical uses of this may include things like saving a player's position in a game so they may come back and play it later, or setting user prefrences for music or color which will be saved for the next time they visit your site.
Also keep in mind you arent just limited to using strings, and integers as data, you may also store arrays and even xml objects (any predefined type of data).