Other communication methodsHere I will focus on my tutorials. The difference is that there are some full-blown tutorials. I will focus on these two methods and an event: load and loadAndSend methods, and onLoad events. If you want to learn more about the LV class, we suggest you check the help: Help → flash help → all books → reference to the language of ActionScript 2.0 → ActionScript class → LoadVars. You can also search for LoadVars directly.
LV and TXT Communication.
Do you want to talk about ASP? How can I start TXT? Haha, don't worry. In fact, the principle of LV and ASP communication is the same as that of TXT communication. TXT files are often used and easy to understand.
For LV and TXT communication, the "variable"/"value" pair data mode must be used in the TXT file. For example, wenben = I want to prepare a FLASH message book. Here, "wenben" is the variable, "I want to do the FLASH message book" is the value, and "=" is their pairing method, that is, the method of establishing a connection. Now, we have created a “lv_shiyan.txt text file, and input: neirong_txt = I want to prepare a FLASH message book. Create a "lv_shiyan.fla" in the same folder and write the code in the first place:
// Set the encoding. Otherwise, garbled characters are displayed.
System. useCodepage = true;
// Instantiate an LV object
Var shiyan_lv = new LoadVars ();
// Load External text
Shiyan_lv.load ("lv_shiyan.txt ");
// After Successful loading
Shiyan_lv.onLoad = function (chenggong ){
If (chenggong ){
// Obtain external text content
Var neirong = shiyan_lv.neirong_txt;
// Output text content
Trace ("the content of the text you load is:" + neirong );
} Else {
// Prompt for loading failure
Trace ("loading failed ");
}
};
Run the above Code and you will see in the output panel that the content in "The text you load is: I want to make a flashmessage book, upload it, and upload it externally" has been successfully loaded. If you are interested, you can change the TXT file name and test the loading failure.
Through the above Code, we learned the following knowledge::
1. How to instantiate an LV object (using the new keyword)
2. How to load external text files with LV objects (using the load method)
3. How to determine whether an external text file is successfully loaded (using the onLoad event)
4. How to obtain and use the content of an external text file after it is loaded successfully.
In an external text file, we use the data format of "variable/value" pairs to be used by LV objects. After the external text file is loaded successfully, the variables are recorded by the LV object, and the LV object is referenced by the LV object in the. variable name in an external text file. The above code is shiyan_lv.neirong_txt.
The above example illustrates the basic principle of LV and TXT communication. Now let's extend it. What if we want to use multiple variables in an external TXT file? The answer is actually very simple. We only need to use multiple "variable/value" pairs in the TXT file and separate each "variable/value" pair. We still use the example lv_shiyan.txt file. This time, we replace the content with the following format:
Neirongw.txt = beat the LoadVar class! & Amp; neirong2_txt = ASP! & Neirong3_txt = I can make a FLASH message board!
Then, replace the code in "lv_shiyan.fla" with the following content:
System. useCodepage = true;
Var shiyan_lv = new LoadVars ();
Shiyan_lv.load ("lv_shiyan.txt ");
Shiyan_lv.onLoad = function (chenggong ){
If (chenggong ){
// Obtain external text content
Var neirong1 = shiyan_lv.neirong1_txt;
Var neirong2 = shiyan_lv.neirong2_txt;
Var neirong3 = shiyan_lv.neirong3_txt;
// Output text content
Trace ("the content of the text you load is:" + neirong1 + "/" + neirong2 + "/" + neirong3 );
} Else {
Trace ("loading failed ");
}
};
Run the above Code. In the output window, we can see the "victory over LoadVar class! /Beat ASP! /I can make a FLASH message board !", This shows that all the variables in the external TXT file are obtained.
If you are interested, you can change the content in “lv_shiyan.txt to the following format to see if the output results have changed:
& Amp; neirongw.txt = beat the LoadVar class!
& Amp; neirong2_txt = ASP!
& Neirong3_txt = I can make a FLASH message board!
Then change to the following result and try the output result again :)
& Amp; neirongw.txt = beat the LoadVar class! &
& Amp; neirong2_txt = ASP! &
& Neirong3_txt = I can make a FLASH message board! &
The reason is actually very simple. Think about it and pull it yourself :)
The following describes the basic format and syntax of ASP, especially the input and output statements.