public data : Object
The collection of attributes assigned to the data property of the object. Each attribute can be an object of any basic ActionScript or JavaScript type--Array, Number, Boolean, and so on. For example, the following lines assign values to various aspects of a shared object.
Note: For Flash Lite, if the shared object listener has not been invoked, the data property could contain undefined values. For details, see the description of the addListener() method.
var items_array:Array = new Array(101, 346, 483);
var currentUserIsAdmin:Boolean = true;
var currentUserName:String = "Ramona";
var my_so:SharedObject = SharedObject.getLocal("superfoo");
my_so.data.itemNumbers = items_array;
my_so.data.adminPrivileges = currentUserIsAdmin;
my_so.data.userName = currentUserName;
for (var prop in my_so.data) {
trace(prop+": "+my_so.data[prop]);
}
soResult = "";
for (var prop in my_so.data) {
soResult += prop+": "+my_so.data[prop] +"\n";
}
result.text = soResult;
All attributes of a shared object's data property are saved if the object is persistent and the shared object contains the following information:
userName: Ramona adminPrivileges: true itemNumbers: 101,346,483
Note: Do not assign values directly to the data property of a shared object (for example, so.data = someValue). Flash ignores these assignments.
To delete attributes for local shared objects, use code such as delete so.data.attributeName; setting an attribute to null or undefined for a local shared object does not delete the attribute.
To create private values for a shared object--values that are available only to the client instance while the object is in use and are not stored with the object when it is closed--create properties that are not named data to store them, as shown in the following example:
var my_so:SharedObject = SharedObject.getLocal("superfoo");
my_so.favoriteColor = "blue";
my_so.favoriteNightClub = "The Bluenote Tavern";
my_so.favoriteSong = "My World is Blue";
for (var prop in my_so) {
trace(prop+": "+my_so[prop]);
}
The shared object contains the following data:
favoriteSong: My World is Blue favoriteNightClub: The Bluenote Tavern favoriteColor: blue data: [object Object]
The following example saves text to a shared object named my_so (for the complete example, see SharedObject.getLocal()):
var my_so:SharedObject = SharedObject.getLocal("savedText");
// myText is an input text field and inputText is a dynamic text field.
myText.text = my_so.data.myTextSaved;
// Assign an empty string to myText_ti if the shared object is undefined
// to prevent the text input box from displaying "undefined" when
// this script is first run.
if (myText.text == "undefined") {
myText.text = "";
}
changedListener = new Object();
changedListener.onChanged = function (changedField) {
my_so.data.myTextSaved = changedField.text;
inputText.text = "";
inputText.text = my_so.data.myTextSaved;
}
myText.addListener(changedListener);