xml| data
Objective:
For the sake of work, for a long time did not write anything like the kind of thing! Recently found that the forum has a common problem, is a question to ask thousands of times also tireless (always some friends thought lazy, to direct questions here, even search is not necessary, here to these friends to criticize, reason you more than I know). According to my various observation, so want to last, thoroughly detailed to some problems in practical application of the problem to a "encirclement and suppression activities." This section is about "flash contact with the outside" Tutorial! This tutorial is for beginners to learn the reference, the master can carry out the batch point (it is best to help modify my error or point out a simpler method, or the file warping as AS2.0 Class), such as the urgent need for the original file, please bypass (nonsense to this end)
The first Lecture: The most basic reading
Loadvariables ()
Loadvariablesnum ()
Usage
Loadvariables ("url", target [, variables])
Loadvariablesnum ("url", level [, variables])
Difference:
The theory of Things I will not say, we all know that Flash has a hierarchy (level), there are movie clips (MC) Then:
• If you want to have the data that flash reads into a movie clip, you can use the first loadvariables
• If you want to get the data that flash reads to a certain level, you can use a second loadvariablesnum
FLASH4 syntax, the function that reads data from an external file (such as a text file, or text generated by a CGI script, Active Server Page (ASP), PHP, or Perl script) and sets the value of the variable in the target movie clip. This action can also be used to update variables in the active SWF file with the new values.
An example is provided:
1, we first prepare a txt notepad. Write the following inside:
t_name=tommyheng&t_age=25 Old &t_from= Liaoning Shenyang
Explanation: The above text content I defined 3 variables T_name t_age t_from and gave them a value respectively. And in the middle with a & separated, not understand the friend will ask? What do you mean by & separation? Then I'll tell you, Flash reads the external data, when the external data is loaded by the program, Flash will automatically split the data according to the & that means the contents of the above text if it is read by Flash, Flash automatically recognize that they are 3 variables.
2, we create a new Flash file, in the first frame written:
Loadvariables ("Tommyheng.txt", "_root");
Or (choose one, don't write 2.)
Loadvariablesnum ("Tommyheng.txt", 0);
Explanation: Load the tommyheng.txt into flash in 2 different ways.
The first method: Load the data in the text into the main scene of Flash (_root is actually the main scene of Flash, of course, if you want to put the data into a flash in a MC, you can change it to, _ ROOT.MC means a movie clip called MC that is loaded into the main scene.
The second method is to load the data in the text into the No. 0 level in the flash scene, and then insert a key blank frame in the 5th frame where it writes
Trace (T_name);
Trace (t_age);
Trace (T_from);
Stop ();
Explanation: Trace () is a information output function in Flash, in the production of flash, developers can use this function, the results returned by the program (variable) directly output to see if the operation is correct and so on, but it can only be used in Flash (ie press CTRL + When you enter it, you can see its function.
Save Flash and Tommyheng text in the same folder. Press Ctrl+enter to test the movie directly, and you will find that the result will be output:
Tommyheng
25
Liaoning Shenyang
If you want to display these results in a text box , rather than output, there are 2 different ways to do this:
The first way : the direct distribution of the way
Just do 3 dynamic text boxes, click each text box separately, find the variable in its properties, and fill in the respective:
T_name T_age T_from
the second way: self- defined distribution mode
Also create 3 dynamic text boxes, but the difference is to select each text box, respectively, in its instance name to fill out the random 3 names, such as: A1 A2 A3
Then write the following procedure on the frame:
A1.text = T_name
A2.text = T_age
A3.text = T_from
This completes the ability of the flash to read external data!!!
Special tips:
Some friends according to my file for testing or learning, there will be a problem, that is the English and digital display is normal, but the Chinese show abnormal garbled (this is a coding problem, very difficult oh). Don't be afraid, we have a way to deal with it, write in the first frame
System.usecodepage=true;
The meaning of this sentence is to let flash know Chinese (hehe), in theory, let flash use the operating system to run the player's traditional code page to interpret external text files.
The conclusion of this lecture:
Although I have only written flash read text TXT file, but it also tried other format files read. If you want, you can change the file extension to. dat even you can change it into. Tommyheng also, it can be ASP. But if you want to read ASP then you have to be ASP oh. At least the output of the ASP is also t_name=tommyheng&t_age=25 old &t_from= Liaoning Shenyang
From then on we can see that, in fact, Flash read nothing, important point, this file output to be able to be the flash of the knowledge is to be & separate variable format
(not finished preface)
Click to download the file