Preface:
I haven't written anything for a long time because of my work! I recently found that there is a common problem in the Forum, that is, a single question can be asked thousands of times and tens of thousands of times. (Some of my friends are too lazy to ask questions directly here, so they don't even need to search, I am here to criticize these friends for reasons you know better than me ). Based on my observations from many aspects, I would like to give a thorough and detailed "encirclement and suppression" to some practical problems ". This section describes how to use FLASH to communicate with the outside world! This tutorial is only for reference by beginners. Experts can submit a batch (it is best to help modify my errors, point out simpler methods, or convert files to AS2.0 classes ), if you urgently need the original file, Please bypass it (this is the end of the nonsense)
Lecture 1: basic reading
| Program code: |
[Copy Code] [run code] |
LoadVariables ()
LoadVariablesNum ()
Usage
| Program code: |
[Copy Code] [run code] |
LoadVariables ("url", target [, variables])
LoadVariablesNum ("url", level [, variables])
Differences:
I will not talk about things that are too theoretical. We all know that there is a level in FLASH and a video clip (MC:
· If you want to put the data read by FLASH into a video clip, use the first loadVariables
· If you want to put the data read by FLASH at a specific level, you can use the second loadVariablesNum.
Flash 4 has some syntax. This function is used to generate texts from external files (such as text files, or text generated by CGI scripts, Active Server Page (ASP), PHP, or Perl scripts) and set the value of the variable in the target video clip. This action can also be used to update variables in the active SWF file with a new value.
Example:
1. Prepare a TXT notepad first. Write the following content:
T_name = tommyheng & t_age = 25 years old & t_from = Shenyang, Liaoning Province
Explanation: In the text above, I defined three variables t_name t_age t_from and assigned them a value. What's more, if they are separated by commas (&), they will ask? What does "use & separate" mean? Let me tell you, FLASH reads external data. When the external data is loaded by a program, FLASH Automatically splits data according to &. That is to say, if the content in the above text is read by FLASH, FLASH automatically recognizes that they are three variables.
2. Create a New FLASH file and write the following in the first example:
LoadVariables ("tommyheng.txt", "_ root ");
Or (just select one and write the other two)
LoadVariablesNum ("tommyheng.txt", 0 );
Explanation: two methods are used to load tommyheng.txt into FLASH.
Method 1: load the data in the text into the home scene of FLASH (_ root is actually the main scenario of FLASH. Of course, if you want to put the data in a MC in FLASH, you can change it to _ root. mc means a video clip called MC loaded into the home scene)
Method 2: load the data in the text to 0th levels in the FLASH scenario
Then, insert a key blank record at 5th, which is written in
| Program code: |
[Copy Code] [run code] |
Trace (t_name );
Trace (t_age );
Trace (t_from );
Stop ();
Explanation: trace () is an information output function in FLASH. When creating FLASH, developers can use this function to return the results (variables) returned by the program) directly output the output to check whether the operation is correct, and so on, but it can only be used in FLASH (that is, press CTRL + ENTER) to see its function.
Save the FLASH and tommyheng text to the same folder. Press CTRL + ENTER to test the video.
You will find the output result:
Tommyheng
25
Shenyang, Liaoning Province
If you want to display these results in a text box instead of an output, you can use either of the following methods:
Method 1: Direct Allocation
You can directly create three dynamic text boxes, click each text box, find the variables in its properties, and fill in the following fields respectively:T_name t_age t_from
Method 2: Custom allocation
Three dynamic text boxes are also created, but the difference is that you can click each text box and enter three random names in the instance Name field, for example, a1 a2 a3.
Then write the following program on the worker:
| Program code: |
[Copy Code] [run code] |
A1.text = t_name
A2.text = t_age
A3.text = t_from
In this way, FLASH completes the function of reading external data !!!
Note:
Some friends may encounter a problem when testing or learning based on my files, that is, the display of English and numbers is normal, however, Chinese characters are not normal and garbled (this is a coding problem, which is very difficult ). Don't be afraid. We have a way to deal with it.
System. useCodepage = true;
The meaning of this sentence is to let FLASH know Chinese (). Theoretically, FLASH uses the traditional code page of the operating system running the player to explain external text files.
Concluding remarks:
Although I only wrote FLASH to read text TXT files, it also tried reading other format files. If you want to, you can change the file extension to. dat or even change it to. tommyheng or ASP. However, if you want to read ASP, you must use ASP. At least the output result of ASP isT_name = tommyheng & t_age = 25 years old & t_from = Shenyang, Liaoning Province
From this point on, it is not difficult to see that FLASH reading does not matter. The important thing is that the output of this file should be recognized by FLASH, that is, the variable format separated
Click to download this file