Shared Objects are like cookies. They are snippets of data created in the SWF which are stored locally on
the user's computer.
Other SWF movies (on the same domain) can then retrieve the stored data. An example SWF movie using this method is provided below.
The example stores data using the Store button and retrieves it with the Get button.
Checking for an existing .sol and stored data
The shared object (or flash cookie) can be used to determine
if a visitor has been to a web page, since we can see if there is data
stored from the visitors previous visit. If the visitor has not been to the
web page we need to create the shared object and populate it with
data. On a Windows OS PC the data is stored with an .sol extension at
"Documents and Settings\userName\Application Data\Macromedia\Flash Player\#SharedObjects."
It is possible to store several different .sol files
on the user's system. It is also possible to store several variables in each .sol. The default maximum storage of .sol's from any
one domain is 100kb. To store more the user must modify their Flash Player's local storage settings.
This is the script used check for an existing .sol and retrieve any existing data:
onLoad () {
so = sharedobject.getlocal("Filename");
_root.MyVar = so.data.word;
}
onLoad(): Checks to see if a shared object
exists. If the object does not exist the event creates the shared object
on a user's machine.
so: The name of our shared object stored
on the SWF.
sharedobject: Defines it as a shared object.
getlocal: Retrieves the file
"Filename": The filename
that is stored locally as Filename.sol
MyVar: The name of a variable in the
SWF that our data will be retrieved to.
word: The variable name in the Filename.sol that contains our data.
In our script above, if there is data found in the word varialable of our .sol it will be extrated to the SWF's
variable named MyVar. If there is no data found MyVar
will contain no data.
Storing data on the user's system
This is the script attached to the Store button to store new data on the users's system:
on (press) {
so.data.word=MyInput;
so.flush();
}
Flush(): Immediately writes a locally persistent shared object to a local file.
Retrieving the stored data
This is the script attached to the Get button to extract the stored data from the user's system:
on (press) {
_root.MyVar = so.data.word;
}
Summary
Flash shared-objects (Flash cookies)
enable Flash movies to save data which persists on a user's system across
multiple sessions or visits to the Flash movie.
They can be used to store user
preferences, or to check whether a visitor is new or returning.
The shared-object can only be
read by movies from the same domain as the movie that created the shared-object.