Package | net.user1.utils |
Class | public class LocalData |
Inheritance | LocalData ![]() |
Since : | Reactor 1.0.0 |
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. To store a value on disk, use the write() 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. The following code stores the value "Colin" in the fieldusername
of the general record userDetails
:
LocalData.write("userDetails", "username", "Colin");
username
of the
general record userDetails
. It stores the retrieved value in a
local variable named uname
:
var uname:Object = LocalData.read("userDetails", "username");
uname
is Object, which is the return type for the read() method.
To narrow the type for a value returned by read(), use a cast. For example,
the following code casts the return of read() to the datatype SomeType:
var someVar:SomeType = SomeType(LocalData.load("someRecord", "someField"));
someField
actually stores an
instance of type SomeType. Otherwise, you should perform the cast
only after testing the datatype of someField using is at
runtime. For example,
var tempVar:Object = LocalData.load("someRecord", "someField"); var someVar:SomeType; if (tempVar is SomeType) { someVar = SomeType(tempVar); } else { trace("Warning: invalid cast attempted."); }
Method | Defined By | ||
---|---|---|---|
Constructor. | LocalData | ||
flush(record:String):void [static]
Immediately writes all locally stored data to disk. | LocalData | ||
read(record:String, field:String):Object [static]
Retrieves a locally saved value. | LocalData | ||
remove(record:String, field:String):void [static]
Removes a locally saved value. | LocalData | ||
write(record:String, field:String, value:Object):void [static]
Stores a value in a local SharedObject. | LocalData |
LocalData | () | Constructor |
public function LocalData()
Constructor. Do not instantiate this class directly.
flush | () | method |
public static function flush(record:String):void
Since : | Reactor 1.0.0 |
Immediately writes all locally stored data to disk.
Parameters
record:String — The name of the record to write to disk.
Must not contain the following characters:
~ % & \ ; : " ' , < > ? # |
read | () | method |
public static function read(record:String, field:String):Object
Since : | Reactor 1.0.0 |
Retrieves a locally saved value.
Parameters
record:String — The name of the record to retrieve.
Must not contain the following characters:
~ % & \ ; : " ' , < > ? # | |
field:String — The specific field to retrieve within
the specified record.
|
Object — The value of the specified field.
|
remove | () | method |
public static function remove(record:String, field:String):void
Since : | Reactor 1.0.0 |
Removes a locally saved value.
Parameters
record:String — The name of the record.
Must not contain the following characters:
~ % & \ ; : " ' , < > ? # | |
field:String — The specific field to delete within
the specified record.
|
write | () | method |
public static function write(record:String, field:String, value:Object):void
Since : | Reactor 1.0.0 |
Stores a value in a local SharedObject.
Parameters
record:String — The name of the record to which to save the value.
Must not contain the following characters:
~ % & \ ; : " ' , < > ? # | |
field:String — The specific field name within which to save the value.
| |
value:Object — The new value for the specified field.
|