FLash notepad [mongodobject]

Source: Internet
Author: User
10. [Flash basic theory 13] FL notepad [mongodobject]
The SharedObject (Local Shared Object) function is similar to a Cookie in a webpage.

Allows the designer to store a small amount of information on the client.

Ideas:

1. Use a script to create two text boxes and two buttons;

2. The two text boxes are title_txt and content_txt respectively for input and display information;
3. The two buttons are save_btn: save the text content, and load_btn: read the text content.





Add the following code to the first frame:
// ================================ Create two text boxes =====
// Create and set the 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 the content text box
_ 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 =====
// Storage 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: export dobject = export dobject. getLocal ("log_save ");
// Connect to the local Shared Object. Note that this is a static method.
So. data. title_txt = title_txt.text;
So. data. content_txt = content_txt.text;
// Store the data whose title and content are 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: export dobject = export dobject. getLocal ("log_save ");
// Connect to the local Shared Object. Note that this is a static method.
Title_txt.text = so. data. title_txt;
Content_txt.text = so. data. content_txt;
// Read the log_save data to the title and content text box. The two statements are the opposite of the storage operation.
};





Flash Charging: Brief Introduction to Concepts and common methods of mongodobject
1. Role of SharedObject: permanently store the shared object on the user's computer. In Flash, we can use functions such as user login, saving diaries, and even saving game disks.



2. SharedObject reference (getLocal ):

Note that the getLocal () method is a static method. The Declaration method is as follows:
Var so: export dobject = export dobject. getLocal ("kookie ");



3. Stored dobject storage (data): The following example implements a simple storage of personal information.
Var my_so: export dobject = export dobject. getLocal ("savedData ");
My_so.data.name = "Alan"
My_so.data.sex = "male"
My_so.data.age = "21"



4. Partial dobject partial reading (data): The following example reads personal information
Var my_so: export dobject = export dobject. getLocal ("savedData ");
Trace (my_so.data.name)
Trace (my_so.data.sex)
Trace (my_so.data.age)



5. Read all dobject (data): Read all attribute objects in combination with the for... in statement
Var my_so: export dobject = export dobject. getLocal ("savedData ");
For (var prop in my_so.data ){
Trace (prop + ":" + my_so.data [prop]);
}



6. Empty dobject clear data (clear ):
Var my_so: export dobject = export dobject. getLocal ("savedData ");
My_so.clear ();
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.