Unity uClientCore > LocalData

LocalData Class

Package

org.moock.util

Availability

UClient for Macromedia Flash v2.0.2

Constructor

none

Class Methods

load(record, field) Loads and returns the specified field value.
save(record, field, value) Saves the specified field value to disk.

Description

The LocalData class stores typed ActionScript data locally on the end-user's hard drive. It saves the data using ActionScript's built-in SharedObject class, but provides a more intuitive, convenient syntax than that of SharedObject.

The services of LocalData are accessed entirely through class (static) methods; the class cannot be instantiated.

The LocalData class offers database-style access to data stored locally. To store a value on disk, use the save() method, specifying the record for the value (i.e., the general namespace), the field for the value (i.e., a specific identifier), and the value itself. For example, the following code stores the value "Colin" in the field username of the general record userDetails:

LocalData.save("userDetails", "username", "Colin");

To load a previously saved value from disk, use the load() method, specifying the desired value's record and field. For example, the following code retrieves the value "Colin" from the field username of the general record userDetails. It stores the retrieved value in a local variable named uname:

var uname:Object = LocalData.load("userDetails", "username");

Notice that the datatype declared for the variable uname is Object, which is the return type for the load() method. If you want to narrow the type for a value returned by load(), you must use a cast. For example, the following code casts the return of load() to the datatype SomeType:

var someVar:SomeType = SomeType(LocalData.load("someRecord", "someField"));

The above cast is, of course, unsafe. You should only use similar code when you are 100% positive that someField actually stores an instance of type SomeType. Otherwise, you should perform the cast only after testing the datatype of someField using instanceof at runtime. For example,

var tempVar:Object = LocalData.load("someRecord", "someField");
var someVar:SomeType;
if (tempVar instanceof SomeType) {
  someVar = SomeType(tempVar);
} else {
  trace("Warning: invalid cast attempted.");
}


Documentation Version

1.0.1