25 July 2010
A shared object is sometimes also known as a local shared object or cookie. Shared objects are used in Adobe Flash Professional to capture and display data submitted based on user interaction with a SWF file.
Using shared objects, you can build applications in Flash that collect and format user-inputted data. Flash offers a variety of ways you can enter and format data in applications. This flexibility exists due to animation and the creative control you have over the application's interface, and the error checking and validation you can perform using ActionScript.
For example, if a game includes a text field where users can enter their name, they can open the SWF file at a later date and Adobe Flash Player can display their name in a personalized greeting in a dynamic text field, like this: "Hi, Joe!"
Other data, such as high scores, can also be collected and displayed in subsequent sessions (if the user maintains the cookie that is set in their browser). Shared objects are also used in forms and shopping carts, to prepopulate the user's name and address in form fields so that they do not have to re-enter the data each time they submit a form or purchase an item.
The following code snippet is a simple mechanism for getting the value of a cookie, if one exists, on the current document and storing it in a variable for future use:
function readCookie(name)
{
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0)
{
offset = document.cookie.indexOf(search);
if (offset != -1)
{
offset += search.length;
end = document.cookie.indexof(";",offset);
if (end == -1)
{
end = document.cookie.length;
}
cookieValue = unescape(document.cookie.substring(offset,end));
}
}
return cookieValue;
}
To preserve information that you collect from the user, save it in a shared object on the user's computer, in a process similar to setting a cookie.
For more information on shared objects, see the sharedObject class documentation in the ActionScript 3 Reference.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License