SoFunction
Updated on 2025-04-13

Introduction to FLASH and ASP Communication Tutorial - Make a Message Book that Really Belongs to You Page 3/5


After studying in the first two sections, we have become familiar with the use of LV classes, as well as the basic format and input and output of ASP. Now let’s see how these two things are integrated together. Do you still remember the TXT example I gave when talking about the basic knowledge of LV class? When LV communicates with TXT, the data in TXT needs to be written in a format that pairs "variable/value". In fact, it must be written in this format is not determined by TXT, it is determined by the characteristics of LV. That is to say, LV communicates with text files with a data format such as "variable/value". ASP files are actually text files. When ASP communicates with LV, the content format it outputs must follow the "variable/value" pairing rules.

Okay, let's have an intuitive experience from the code. We also use the example of passing multiple variables mentioned in the section "★LV Class Basic Explanation". Remember the name of the TXT file: "lv_shiyan.txt". Okay, now we directly change "lv_shiyan.txt" to "lv_shiyan.asp", and also replace lv_shiyan.txt in the sentence shiyan_lv.load("lv_shiyan.txt") in the code "lv_shiyan.fla" with lv_shiyan.txt" and then directly press Ctrl+Enter to test the video in the FLASH editing environment. We found that the output window output: "Battle against the LoadVar class! /Battle against the ASP! /I can do FLASH message board!", the same as before.
faint! This is OK! ? What is this? Is it a communication between FLASH and ASP? Why don't IIS be needed? Is that FLASH and TXT communication? But the suffix name of someone else is obviously ".asp"! ? In fact, Volcano doesn't understand it very well, but I prefer to understand it as the communication between FLASH and ASP, just because there are no ASP statements in this ASP file and the content can be displayed without IIS support. If you have to ask for an explanation, the most conservative answer is: FLASH communication with text files:)

Haha:) Okay, I won’t fool everyone. It doesn’t matter if I don’t understand the above paragraph. In fact, the purpose of my transition from TXT to ASP is to tell you more intuitively: FLASH shows that the content in ASP is consistent with TXT. As long as we find a way to tinker with the data format output by ASP into "variables/values" pairing!

After wandering around in TXT for so long, everyone is anxious. OK, now I'm going to play it real, ASP officially debuted:
First, we change the content in "lv_shiyan.asp" to the following form:

★LV and ASP communication principle<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
("&neirong1_txt=By the LoadVar class!&neirong2_txt=By the ASP!&neirong3_txt=I can do FLASH message board!&");
%>

Let's run it under IIS first, and the following content will be displayed on the web page:

★LV and ASP communication principle
&neirong1_txt=By defeating the LoadVar class! &neirong2_txt=By defeat ASP! &neirong3_txt=I can do FLASH message board! &

kindness! ? Why does it look so familiar? Congratulations, you answered correctly. Isn’t this the content in “lv_shiyan.txt”! But the title after "★" has been replaced by the title of this section:) OK, then, you, smart, have you expected what I want to do next? Congratulations, you answered correctly again. Why are you so smart? The next step is of course to display these data in FLASH. Just do it, return to the editing environment of "lv_shiyan.fla" and press Ctrl+Enter again to test the video. Haha, it succeeded! The output window shows: "Battle against the LoadVar class! /Battle against the ASP! /I can make the FLASH message board!" Hahahahaha-oh! What about you, why are you laughing at? I am happy because I finally fooled you again. Why are you laughing at? Look at our "lv_shiyan.asp" file. We have clearly written the ASP statement, but why can we display it directly in the FLASH editing environment without IIS support? Does our FLASH software run under IIS? Of course this is impossible, so how could it be? Hehe:) Okay, no headache for everyone. In fact, when we first changed "lv_shiyan.txt" to "lv_shiyan.asp" and ran the video test, the data in "lv_shiyan.asp" had been read into memory. Later, although we changed the content in "lv_shiyan.asp" to the output format unique to ASP, since the file name has not changed, when running the video test, FLASH will still directly extract the stored content from memory, and the last content did not require IIS, which happened to be :)

So how do you display new content? We just need to use random functions to pass a variable that has no practical significance to ASP. We can change the statement that loads ASP to the following:

shiyan_lv.load("lv_shiyan.asp?bianliang="+random(9999));

Now test the video in FLASH again and find the following prompts in the output window:

Loading failed
Error opening URL "file:///E|/flashlianxi/flash and asp exercises/FLASH and ASP communication introductory tutorial/lv_shiyan.asp?bianliang=5624"

kindness! ? There is another problem. Isn’t it that “bianliang” has no practical meaning? How can it cause "Error opening URL"? Haha:) Actually, the "no practical meaning" mentioned here is for ASP, or rather, for browsers. Do you still remember the GET delivery method I mentioned in the "★Basic Input and Output in ASP" section? If you forget for a while, you can go back and review. Actually, my suggestion is that you can follow my progress and thoroughly understand each section. After I finish writing it, read it through, and then you can make a message board by yourself. Following the above, since this "no practical meaning" is not for FLASH, then FLASH will definitely not recognize it. It will regard "lv_shiyan.asp?bianliang=5624" as file names, so of course this file cannot be found.

It's time to clear the clouds and see the sunny day. Now we first add a dynamic text field to "lv_shiyan.fla" and name it "wenben_txt", and then change the output code to let the content originally displayed in the output window be displayed in the dynamic text field. The specific change is to change the following first line of code to the second line:
trace("The text content you load is: "+neirong1+"/"+neirong2+"/"+neirong3);
wenben_txt.text = neirong1+"/"+neirong2+"/"+neirong3;
Okay, finally release "lv_shiyan.swf" and "lv_shiyan.html" to the same folder as the ASP file, and run "lv_shiyan.html" under IIS. You will see the dynamic text field of SWF displaying "Battle of LoadVar!/Battle of ASP!/I can do FLASH message board!", and now you can finally cheer with confidence: we can finally display the content output of ASP in FLASH, haha...

Let’s have a drink of water first. It’s almost two hours in the blink of an eye. Why do I write so slowly? Come on! What we talked about above is actually how ASP transmits information to FLASH. This is not a real interaction. The interaction is interaction between the two parties. Now let’s take a look at how FLASH transmits information to ASP. Before this, please make sure you still remember how ASP received a variable in the "★Basic Input and Output in ASP". We also used the "asp_jichu.asp" file used in that section. At that time, I assigned the value of "neirong_wangzhi" directly in the browser address bar through GET, and the test proved that ASP did receive the value of this variable through Request. Now we want FLASH to do what the address bar does, and we need to assign "neirong_wangzhi" through FLASH.

Before we officially start, we have the following work to complete

1. Add another button to "lv_shiyan.fla" and name it "tijiao_btn".
2. Change the dynamic text field "wenben_txt" into the input text field, cancel the HTML output, and change the name to: "shuru_txt".
3. Add a dynamic text field to receive the information returned from the ASP, named "shuchu_txt".
4. Change the content in "asp_jichu.asp" to the following content:
★Basic input and output in ASP<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
var neirong;
//Get the variable passed from FLASH
neirong=Request("neirong_flash");
//The output is to return to the content in FLASH
("&fanhui_asp=Ha, the content you entered has been passed to the ASP and has returned to FLASH from the ASP. The content you entered is: "+neirong);
%>

5. Finally, change the code in "lv_shiyan.fla" to the following content:
= true;
var shiyan_lv = new LoadVars();
tijiao_btn.onRelease = function() {
//Get the input text content and record this content in the variable "neirong_flash"
//This is equivalent to having already assigned the variable "neirong_flash"
  shiyan_lv.neirong_flash = shuru_txt.text;
//Pass all variables stored in the LV object to the ASP, but here we only set one, which is our "neirong_flash"
//After the transmission to ASP is successful, we will store the variables passed back from ASP in the "shiyan_lv" object.
  shiyan_lv.sendAndLoad("asp_jichu.asp?bianliang="+random(9999), shiyan_lv, "post");
};
shiyan_lv.onLoad = function(chenggong) {
  if (chenggong) {
//Output text content
    shuchu_txt.text = shiyan_lv.fanhui_asp;
  } else {
//Output text content
shuchu_txt.text = "Loading failed";
  }
};

Huhu, there are so many things that have been modified. I won’t talk about the code first, just post and test it. First, I have an intuitive understanding: enter "I want to do FLASH message board" in the input text box, and then click the submit button, and you will see that in the dynamic text box "shuchu_txt", it will immediately display: "Ha, the content you entered has been passed to the ASP, and has returned from the ASP to FLASH. The content you entered is: I want to do FLASH message board". The source file of this example can also be downloaded directly below.

Tips: If you click Refresh directly in the browser, it cannot correctly display the updated page and content, please set the IE browser as follows: → Tools → Internet Options → Settings → Hook to select "Check every time you access this page". In this way, we can directly use refresh to test in the future, and we no longer have to worry about IIS refresh and memory problems.

Finally, let’s conduct a systematic analysis of the data process during the test process.

  • The user enters "I want to do FLASH message board" in the input text box "shuru_txt" of FLASH
  • The code "shiyan_lv.neirong_flash = shuru_txt.text;" stores the content input by the user in the "neirong_flash" of the "shiyan_lv" object
  • Pass all the variables it records to the specified ASP file through the "sendAndLoad" method of the "shiyan_lv" object
  • In the ASP file, use the code "neirong=Request("neirong_flash");" to obtain the variable "neirong_flash" passed from the "shiyan_lv" object of FLASH in the ASP file.
  • After receiving variable content, ASP calls the Write method of the Response object to use the passed variable content in the format of "variable/value" pairing output. The new content of FLASH needs to be returned.
  • When FLASH calls the "sendAndLoad" method of the "shiyan_lv" object to send a variable, it already specifies that "shiyan_lv" itself receives the returned content.
  • "shiyan_lv" receives the newly returned content and stores the new content in "shiyan_lv.fanhui_asp" according to the format of its "variable/value" pairing.
  • When the newly returned content is loaded in FLASH, the onLoad event of the "shiyan_lv" object is called
  • The code "shuchu_txt.text = shiyan_lv.fanhui_asp;" displays the newly returned content in the output text box
    After this analysis, I believe everyone should have a rational understanding in general.

Finally, some points that need to be emphasized are

  • When the LV object calls the "sendAndLoad" method to send variables, it will send all the variables stored in the LV object to the ASP.
  • When ASP receives variables passed by LV objects, it only needs to use the same variable name as in FLASH in Request.
  • The data output by ASP must use the "variable/value" pairing format, because only if the output is in this format can FLASH record the data output by ASP in several variables and save them in the LV object that specifies the received data as if it were TXT.
  • If we want to pass two or more variables to FLASH, we can write this in FLASH: (Taking passing three variables as an example)
    shiyan_lv.bianliang1_flash="bianliang1";
    shiyan_lv.bianliang2_flash="bianliang2";
    shiyan_lv.bianliang3_flash="bianliang3";
    shiyan_lv.sendAndLoad("asp_jichu.asp?bianliang="+random(9999), shiyan_lv, "post");
  • When passing large amounts of data, the POST method must be used.
  • If we want to receive multiple variables passed from FLASH in FLASH, it will be OK according to the TXT processing method.

Huh, take a breath, this section is finally finished. I originally planned to write "Comprehensive Application of LV and ASP" next time, but now thinking about it, it is still necessary to add a section "Beginner of ASP Operation Database", please continue to pay attention. If you have any good opinions, you can also mention them. I hope that through everyone's joint efforts, this tutorial will allow the novices to create their own FLASH message board with the fastest speed and least obstacles.

Remember that meaningless variable "bianliang" we passed to ASP? Since we have passed it to the ASP, the ASP should be able to receive it. Interested friends can add a statement to receive variables in "asp_jichu.asp" to test the effect. The modified ASP code is as follows:

★Basic input and output in ASP<br>
<%@LANGUAGE="JAVASCRIPT"%>
<%
var neirong;
var canshu;
//Get the content of the variable in the URL
neirong=Request("neirong_flash");
//Get meaningless parameters
canshu=Request("bianliang");
//Show variable content
("&fanhui_asp=Ha, the content you entered has been passed to the ASP and has returned to FLASH from the ASP. The content you entered is: "+neirong+". The meaningless parameter you passed is: "+canshu);
%>

After testing, I found that I could really receive a number, and the number submitted by each point is almost different, changing between 0-9999. It seems that we have indeed received random variables passed by FLASH, but why isn't it displayed in the address bar when it is passed? This time we use the "POST" delivery method, which is used to pass a large amount of data and will not display variables and their values ​​in the address bar.

FLASH and ASP interaction examples

Previous page12345Next pageRead the full text