On the principle of other communication methods
Here I will mainly focus on my tutorials, to distinguish some of the overall indoctrination of the tutorial, I would have a real focus on this class of two methods and an event: Load, Loadandsend method, and onload events. If you need a more detailed understanding of the LV class, suggest you check help: Help →flash help → all books →actionscript 2.0 Language Reference →actionscript class →loadvars. Of course you can also search loadvars directly.
LV and TXT newsletter .
Not to talk about ASP? How do you speak of txt? Oh, do not worry, in fact, the LV and ASP communication principle and the principle of txt communication is the same. TXT you often use, speaking up more easily understand.
LV and TXT communication need to use the "variable"/"value" pairing data mode in TXT. For example: wenben= I want to do flash message book. Here "Wenben" is a variable, "I want to do flash message book" is the value, and "=" is their pairing way, that is, the way to establish contact. OK, now we build a "lv_shiyan.txt" text file and enter in it: neirong_txt= I want to make a flash message book. Then in the same folder to create a "Lv_shiyan.fla", in the first write code:
Set the encoding, or it will display garbled
System.usecodepage = true;
Instantiate a 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) {
Get External text content
var neirong = Shiyan_lv.neirong_txt;
Output text content
Trace ("The textual content that you load is:" +neirong);
}else{
Load failure give prompt
Trace ("Load failed");
}
};
Run the above code, you will see in the output panel "You loaded text content is: I want to do flash message book", this shows that the external "lv_shiyan.txt" in the content has been successfully loaded. Interested friends can change the txt filename, test the failure of loading.
through the above code, we learned the following knowledge :
1, how to instantiate a LV object (using the New keyword)
2. How to load an external text file with the LV object (using the Load method)
3, how to determine whether the external text file is loaded successfully (using the OnLoad event)
4, how to obtain and utilize the contents of an external text file after it has been successfully loaded.
In an external text file, we use the "variable/value" pairing data format, in order to be used by the LV object, when the external text file loaded successfully, the variables will be recorded by the LV object, and in as as the LV object reference external variables in the way: Lv object. The name of the variable in the external text file. The above code is: Shiyan_lv.neirong_txt.
The above example tells the basic principles of LV and TXT communication, and now let's expand, what if we want to use multiple variables in an external txt? The answer is actually very simple, we only need to use multiple "variable/value" pairs in txt, and separate each "variable/value" pair with "&". We still use the "lv_shiyan.txt" file of the above example, this time to change the contents of the content into the following form:
Neirong1_txt= beat Loadvar Class! &neirong2_txt= victory over asp! &neirong3_txt= I can make flash message board!
Then replace the code in "Lv_shiyan.fla" with the following:
System.usecodepage = true;
var shiyan_lv = new Loadvars ();
Shiyan_lv.load ("Lv_shiyan.txt");
Shiyan_lv.onload = function (Chenggong) {
if (Chenggong) {
Get 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 textual content that you load is:" +neirong1+ "/" +neirong2+ "/" +neirong3 ");
}else{
Trace ("Load failed");
}
};
Run the above code, in the Output window we can see "Beat Loadvar Class!" /victory over asp! /I can make flash message board! , which shows that we have all the variable contents in the external txt.
Interested friends can change the contents of "Lv_shiyan.txt" into the following form to see if the output has changed:
&neirong1_txt= beat Loadvar Class!
&neirong2_txt= victory over asp!
&neirong3_txt= I can make flash message board!
And then we'll try it again. Output results:)
&neirong1_txt= beat Loadvar Class! &
&neirong2_txt= victory over asp! &
&neirong3_txt= I can make flash message board! &
The reason is actually very simple, oneself think about pull:
Shout, OK, LV class first here, the basic format and syntax of ASP, especially input and output statements.
Current 1/5 page
12345 Next read the full text