Back to "flash Basic Theory Class-Catalog"
Sharedobject (local shared objects) feature similar to cookies in Web pages
Allows the designer to store a small amount of information on the client
Ideas:
1. Create two text boxes and two buttons with a script;
2. Two text boxes are title_txt and content_txt for input and display information respectively;
3. Two buttons are save_btn: Save the text content, LOAD_BTN: Read the text content.
Add the following code to the first frame:
==================== Create two text boxes ====================
Create and set a title text box
var t_f:textformat = new TextFormat ();
T_f.size = 20;
_root.createtextfield ("Title_txt", 1, 10, 10, 150, 25);
With (Title_txt) {
border = true;
BorderColor = 0x0;
Type = "Input";
Setnewtextformat (T_f);
}
Create and set Content text boxes
_root.createtextfield ("Content_txt", 2, 10, 40, 150, 150);
With (Content_txt) {
border = true;
BorderColor = 0x0;
Type = "Input";
WordWrap = true;
Setnewtextformat (T_f);
}
==================== Create two buttons ====================
Save button
_root.createemptymovieclip ("Save_btn", 3);
Save_btn.createtextfield ("TXT", 0, 0, 0, 40, 20);
Save_btn.txt.text = "Save";
save_btn._x = 50;
save_btn._y = 200;
Save_btn.onrelease = function () {
var so:sharedobject = sharedobject.getlocal ("Log_save");
Connect to a local shared object, note that this is a static method
So.data.title_txt = Title_txt.text;
So.data.content_txt = Content_txt.text;
Data that stores title and content information as Log_save
};
Read button
_root.createemptymovieclip ("Load_btn", 4);
Load_btn.createtextfield ("TXT", 0, 0, 0, 40, 20);
Load_btn.txt.text = "Load";
load_btn._x = 100;
load_btn._y = 200;
Load_btn.onrelease = function () {
var so:sharedobject = sharedobject.getlocal ("Log_save");
Connect to a local shared object, note that this is a static method
Title_txt.text = So.data.title_txt;
Content_txt.text = So.data.content_txt;
Reads the Log_save data into the title and content text box, which is exactly the opposite of the storage operation
};