SoFunction
Updated on 2025-04-13

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


Comprehensive use of LV and ASP (II)

Continuing the previous section, now start the third step: "Delete" function:
At the end of the section "Address to Get Started with ASP Operation Database", I gave a SQL statement to delete a record. I wonder if you tried it yourself. If not, it doesn't matter. Now let's implement this function in FLASH with me. And I'll demonstrate how to use "" a background file to achieve all functions.

Before reading the code, please think about this question first. If you want to delete a record, what will you delete it based on? Is it OK to use the "yuwen" score? Open our database table and you can see that "Mao Ning", "Gong Li" and "Bruce Lee" both have 100 points. If we delete the records with a Chinese score of 100, we will delete the records of these three people at the same time. In order to avoid this, we generally rely on fields with the data type "auto-numbered" because the automatic numbering field will never be repeated, such as "xuhao" here.

According to my development habits, we should write the background first. Please write the following code in "":

<%@LANGUAGE="JAVASCRIPT"%>

<%
//Create a database link object
lianjie = ("");
//Open the database
("driver={Microsoft Access Driver (*.mdb)};dbq=" + (""));
//Create "Record Set"
rs = ("");
//Set an option variable and determine the code to execute the corresponding function based on the value of this option. This variable comes from FLASH
var xuanxiang=Request("xuanxiang_flash");
%>

<%
//———————Decide to call the corresponding function based on the variable "xuanxiang"
if(xuanxiang=="Show"){
//Query display record demonstration
  xianshi();
}else if(xuanxiang=="Delete"){
//Delete record demonstration
  shanchu();
}
%>

<%
//————————Define the function function of "display"
function xianshi(){
//Query SQL statement
sql="select * from shujubiao order by xuhao desc";
//Execute database query
(sql, lianjie, 3);
//Receive the current page number from FLASH
var dangqianye=Request("dangqianye_flash");
//Receive the number of records displayed per page from FLASH
var meiyejilu=Request("meiyejilu_flash");
//Declare a variable to store the content to be output, initially empty
var shuchuneirong="";
//Set the number of records displayed on each page
=meiyejilu;
//Set the currently displayed page number
=dangqianye;
//Get the total number of records
var zongtiaoshu=;
//Get the total number of pages
var zongyeshu=;
//Cycle to display all contents of a page, the specific page number is specified in the "" in the second code
for (i=0;i<meiyejilu;i++){
  if(!){
//Get the field content
  var xuhao=rs("xuhao");
  var xingming=rs("xingming");
  var yuwen=rs("yuwen");
  var shuxue=rs("shuxue");
//Record the content to be displayed in "shuchuneirong"
shuchuneirong =shuchuneirong+"<br>Serial number: "+xuhao +" | Name: "+xingming+" | Chinese: "+yuwen+" | Mathematics: "+shuxue;
  ();
  }
}
//Output the query content into variable/value pairing form
("&neirong_asp="+shuchuneirong);
//Total number of output
("&zongtiaoshu_asp="+zongtiaoshu);
//Output total page count
("&zongyeshu_asp="+zongyeshu);
}
%>

<%
//————————Define the function function of "delete"
function shanchu(){
//Receive the serial number ID passed from FLASH
var id=Request("xuhao_flash");
//Deleted SQL statement
sql="delete from shujubiao where xuhao="+id;
//Execute database query
(sql, lianjie, 3);
}
%>

Note: Comparing the ASP code given in the previous section, sharp-eyed friends will definitely find a few differences

  • The last piece of code to close the connection is gone, why delete it? This is to use a connection object and recordset object multiple times in the same ASP file. In fact, it is not recommended to do this in the formal writing style. This is just for the convenience of demonstration and explanation. When you make your own message book in the future, it is recommended that each function function redeclare the connection object and recordset object and close it at the end of the function.
  • The last paragraph adds a "shanchu" function, which receives the record number passed from FLASH and executes the delete statement.
  • In the functional logic code area of ​​the third paragraph, call the "shanchu" function.
  • The SQL statement in the xianshi" function has a paragraph at the end: "order by xuhao desc", which allows the records to be arranged in reverse order of the xuhao field. This serves the "add" function in the future. It can display the latest added records on the top, making it easier for us to observe. We can ignore it here.

OK, the background file is done, now go back to FLASH and complete our deletion function :)
Open "", enter the following code:

//===================== System initialization=====================================================================================================================================================================================================================================
//———————Interface initialization
//coding
= true;
//——————Variable Initialization
//Declare an "option" variable, and the ASP will determine which function is currently being demonstrated based on this variable in the ASP
//Initialize this variable to "Show" to display records
var xuanxiang = "Show";
//The current page is initially page 1
var dangqianye = 1;
//The number of records per page is initially 5
var meiyejilu = 5;
//—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
//————————Object Initialization
//LV object, used from top to bottom to "Show", "Delete", "Add", and "Update" demonstration in turn
var xianshi_lv = new LoadVars();
var shanchu_lv = new LoadVars();
var tianjia_lv = new LoadVars();
var gengxin_lv = new LoadVars();
//=============================================================================================================================
//—————————— Display function test
xianshi();
//—————————Delete function test
shanchu_btn.onRelease = function() {
shanchu();
};
//====================== Function module area====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
//——————— “Show” function
function xianshi() {
//Set the option to "Show"
xuanxiang = "Show";
//LV object gets the "options" content
  xianshi_lv.xuanxiang_flash = xuanxiang;
//Get “Current Page”
  xianshi_lv.dangqianye_flash = dangqianye;
//Get “Number of records per page”
  xianshi_lv.meiyejilu_flash = meiyejilu;
//Pass the above obtained content to FLASH
  xianshi_lv.sendAndLoad("?bianliang="+random(9999), xianshi_lv, "post");
//A series of related information is displayed after loading
  xianshi_lv.onLoad = function(chenggong) {
    if (chenggong) {
//Show the current page (obtained directly from FLASH)
      dangqianye_txt.text = dangqianye;
//Show the number of records per page (obtained directly from FLASH)
      meiyetiaoshu_txt.text = meiyejilu;
//Show the total number of pieces, total pages and the recorded content of this page
      zongtiaoshu_txt.text = xianshi_lv.zongtiaoshu_asp;
      zongyeshu_txt.text = xianshi_lv.zongyeshu_asp;
      neirong_txt.htmlText = xianshi_lv.neirong_asp;
    } else {
neirong_txt.htmlText = "Loading failed!";
    }
  };
}
//————————— “Delete” function
function shanchu() {
//Set "Options" to "Delete"
xuanxiang = "delete";
//Record the "option" set to "delete" on the LV object used for deletion
  shanchu_lv.xuanxiang_flash = xuanxiang;
//Get the record number to be deleted and also recorded in the LV object
  shanchu_lv.xuhao_flash = shanchuxuhao_txt.text;
  shanchu_lv.sendAndLoad("?bianliang="+random(9999), shanchu_lv, "post");
  shanchu_lv.onLoad = function() {
//Compact operations based on the "success" transmitted back by ASP
if (shanchu_lv.chenggong_asp == "Success") {
shanchuxuhao_txt.text = "Delete successfully";
// Finally, call the "Show" function and refresh the content display in the "neirong_txt" text box
      xianshi();
    } else {
shanchuxuhao_txt.text = "Delete failed";
    }
  };
}

illustrate: We can compare the code in FLASH above to see that the code in ASP has been added. A delete function has been added to the last paragraph in FLASH, and a "shanchu" function is added to the code in this function. I believe everyone can understand the code in this function by referring to the comments now. Then the "Function Logic Area" calls the delete function through the "Delete" button. Finally, there is a little change. I won’t examine everyone’s eyesight here. Please pay attention. I added a sentence to the first line of the “xianshi” function: xuanxiang="Show". This is to make the "xianshi" function more independent. In the "shanchu" function, when the deletion is completed, I called the "xianshi" function so that everyone can see the results after deletion in FLASH in time. If "xianshi" is not defined in "xianshi", when the "xianshi" function is called in the "shanchu" function, the value of "xianxiang" is still "shanchu", so the "xianshi" function in ASP cannot obtain the correct parameters, and the deleted content is displayed.

OK, after saying so much, the exciting time has arrived, let's open "" under IIS to test it. Just open it and you will see the correct page number and content display. Then, you enter "13" in the deleted input text box and press the "Delete" button. When this input text box prompts "Delete successfully", you will immediately see that the "Total Record Number" has changed from the original 13 to 12, and the record with "xuhao" of 13 in the content text box disappears. The poor "Zhao Wei" was eliminated by us just a little :)
After this demonstration of the "delete" function, I believe everyone has a certain understanding of my ideas and function expansion methods. Below I will complete the "Add" and "Update" function demonstration at one time!

Step 4: "Add" and "Update" functions:
I won’t post the code in this step. You can download the source file directly, because there is really nothing to say. What you need to do in this step is to add the corresponding function blocks in ASP and FLASH according to the previous pattern, and then call the corresponding function functions in the "logical functional area". It is said that a well-organized program is more complicated at the beginning, but the more you write it, the easier it is. I think a good tutorial should be the same :)

A brief summary: The core content of this tutorial is basically finished here. The basic functions of a FLASH message book are almost implemented, but the distance between imagination and the finished product is actually a short distance. If you want to make a FLASH message book with complete functions, it is far more than what I have talked about. There are still many techniques and details here, mainly depending on your basic skills in AS and ASP! Anyway, I have taught you all the ways to catch fish. Whether you can catch fish still needs to be done through everyone's own practice and efforts. Actually, I have left you a lot of homework, including page turnover processing, management login, etc., but as long as you really understand the principles I mentioned earlier, it is indeed not difficult to do it yourself. But if you still have no idea at all, it is probably necessary to read my tutorial from beginning to end again. It is not scary to learn only one knowledge point in a long time. I am afraid that you have learned a lot of knowledge points in a long time, but none of them have really learned it!
Finally, if anyone has made a FLASH message book that truly belongs to him through his own efforts, don’t forget to post it to let Volcano and his comrades appreciate it. Volcano has not been in vain for so long :)

One of the comprehensive use of LV and ASP:demo4

Yesterday, I wrote the previous section without much, so I went around the forum. I accidentally found a post written by the classic "handmade relationship" of the Bamboo. It summarized three common methods of communication between FLASH and ASP, including loadVariables, LoadVars and XML, and some in-depth discussions with the posts. I think it is very good. If you are interested in which method, you might as well read the posts of your predecessors. Volcano will no longer nag here. There is only one way they didn't mention, which is getURL. Let me focus on this communication method.
Tutorial on handmade emotional bamboo:/?tid=1113968&highlight=
Taking this tutorial, let’s mourn this selfless senior who is dedicated - every selfless devotee in Blue should not be forgotten!

Continuing my tutorial, what's special about getURL is that it can open a new ASP web page and make the web page receive the passed variables, so that the ASP web page can be set and displayed according to this variable. This technology is used in my FLASH BLOG. Unfortunately, getURL cannot specify the number of variables passed. It will pass all variables at the same level to the ASP very mechanically. If you mix statements calling the getURL function with a large number of other AS statements, you will inevitably pass a large number of garbage variables. The solution is to write the variables to be passed and the statements calling the getURL function in an independent MC. Here I will briefly demonstrate its usage:

1. First create a "" file and "" file in the same directory.
2. Enter the following code in "":

<%@LANGUAGE="JAVASCRIPT"%>
<%
//Receive variable
var neirong1=Request("neirong1_flash");
var neirong2=Request("neirong2_flash");
var neirong3=Request("neirong3_flash");
//Show variable content
("The value of content 1 is "+neirong1+"<br>");
("The value of content 2 is "+neirong2+"<br>");
("The value of content 3 is"+neirong3);
%>

3. Create a button "anniu_btn" in "" and write the code on Zhen:

var neirong1_flash = "neirong1";
var neirong2_flash = "neirong2";
anniu_btn.onRelease = function() {
  getURL("", "_blank", "get");
};

In this way, the preliminary work will be completed. Let’s conduct a series of comparative tests:

① Directly publish the test. When we click the button, we will find that "" is newly opened, and the page shows:

The value of content 1 is neirong1
The value of content 2 is neirong2
The value of content 3 is undefined

It seems that we do receive the variables neirong1_flash and neirong2_flash. Since neirong3_flash is not defined in FLASH, we get undefined in ASP. Now let's pay attention to the URL suffix of the ASP web page:

?neirong1%5Fflash=neirong1&neirong2%5Fflash=neirong2

This suffix is ​​URL encoded, and translated into:

?neirong1_flash=neirong1&neirong2_flash=neirong2

Do you think its format is very familiar? The answer is correct! It is the "variable/value" pairing that we have always emphasized before. Its variable transmission principle follows the same rule as that of LV! How about it? Now I understand what is a one-to-one game, and I’ll use it to the same as the same as the data format in TXT. One thing to explain is that when multiple "variable/value" pairs are passed, they are separated by "&", which is the same as the data format in TXT.

② Change the "get" delivery method in the "getURL" function in "" to "post" and test it again. You will find that the ASP web page has no suffix in the browser URL, but the web page display results remain unchanged.

③Now we change the "getURL" function in "" to the following form:

getURL("?neirong3_flash=neirong3", "_blank", "get");

After posting a test, we will find that after clicking the button, the content displayed by the opened ASP web page has changed. Neirong3 received the value, and the content displayed by the web page is as follows:

The value of content 1 is neirong1
The value of content 2 is neirong2
The value of content 3 is neirong3

Observe the browser URL suffix:

?neirong3_flash=neirong3&neirong1%5Fflash=neirong1&neirong2%5Fflash=neirong2

You can find that there is an additional "neirong3_flash=neirong3&" and it does not perform URL encoding. This point is not very understandable. Why do you do not perform URL encoding by writing variables directly in the ASP file call statement? I hope a senior expert will point out and thank you for your own sake.

What needs to be noted here is: I have seen some people say that the "getURL" function can pass the specified variable by adding parameters after the called file name, which is actually a visual misleading. getURL always passes all variables, but those garbage variables cannot be seen if you don't test them.

④ Finally, I will give you a big gift to put a perfect end to this tutorial. This gift is "the way of thinking in tests":

There are three variables
There are two ways to write variable passing: write it directly after the file name or declare and assign a value in the timeline.
There are two ways to pass variables: get and post

So there are a total of 3*2*2=12 possibilities for testing. I only did 4 representative ones, leaving the others for readers themselves.

Haha, how about it, this kind of idea is easy to understand, right? Unfortunately, everyone understands the truth, and practice is always difficult!

Classic forum discussion
/