Application of Flash combined with ASP database

Source: Internet
Author: User
Tags variables query reference urlencode access database
Data | database

Before discussing the example, first understand the flash and ASP combination principle, actually understand a little ASP's friends know ASP is based on HTML. Flash and ASP interface principle and pure ASP file interaction principle is the same, simply say is the data exchange between pages.

and passing data between pages is implemented through functions:

Loadvariables (Flash4 version)/loadvariablesnum (Flash5 version, FLASHMX version)

Grammar:

Loadvariables (URL, location [, variables]);
Loadvariablesnum (URL, location [, variables]);

Parameters:

The URL is the location of the S script file that needs to be loaded.
Location, load into the SWF location.
Variables is an indication of whether you need to pass parameters, there are post and get two options.

Description

Flash is a very important technique, and external files for data exchange, if you can use this, this is undoubtedly expanding the scope of the application of Flash.

Flash can accept the variable format is: variable name = variable value, Flash support multivariable acceptance, the format of a number of variables separated by & can be. And there are three ways to accept variables.

First: Flash can directly accept variables for HTML files.

Methods are as follows

1. The statement that invokes the SWF file:

<param name=movie value= "Your swf file. swf" >
Change to: <param name=movie value= "Your swf file. swf? variable name = variable value >

At this point, the variable is accepted in the SWF file.

2. If you want to transfer multiple variables in the same HTML file, the writing format is:

<param name=movie value= "Your swf file. swf? variable Name 1 = variable value 1& variable Name 2 = variable Value 2& variable name 3 = variable Value 3" >.

3. Running HTML files, you can directly display or reference variables in SWF.

(when actually used, '? ' Directly with ' & variable name ' to pass the value to the past.

The above is through the HTML call SWF with parameters to pass parameters to flash, but Flash and external file "marriage" the most typical method is the direct reading is TXT file and CGI, PHP, ASP files. The former can be run on the client and the latter for server support. This is what we are now speaking of the command load variables, the following we will talk about the specific implementation process.

  Second: Read the variables from TXT file:

1. Create a TXT file, the file variable writing format is:

M1= This is flash read TXT file

Where "M1" is the variable name, "This is the Flash read TXT file" is the variable value.

2. If you want to set multiple variables in the same TXT file, the writing format is:

M1=data1 & M2=data2 .....

3. Setting up Actions

Select "Load Variables into Location"

Enter your txt filename (for example, sunyue.txt) in the URL input box. Note If you have a path, be sure to add a relative or absolute path.

All actions are as follows:

Loadvariablesnum ("Sunyue.txt", "0")

We can see more clearly in the picture.

This will then be able to directly display or reference m1,m2 in Flash ... and other variables. It is important to note that these variables must be used in the MC layer defined in the load Variables command, in the above example, M1, M2 ... Are all present at level 0.

Third: Read the variable from the cgi,php,asp file:

For these background program languages, this is not intended to be described in detail, only about the contents of the Flash read part. In fact, the truth is also very simple, as the above read from the text file into the data, as long as the results of the implementation of these daemons is to show "variable name = the value of the variable ..." It's OK.

Metaphorically, if it's a CGI, it's the print "Variable name = value of the variable ..." PHP, is the echo "Variable name = value of the variable ..."; if it is an ASP, then of course it should be Response.Write "Variable name = value of the variable ..." Out. and the specific call process, and the above call from the TXT file call the same, but the Flashtxt.txt file into your ***.cgi, ***.php, ***.asp file on the line.

Here, we can also talk about a load variables and daemon another use-pass variables, when we use to write HTML pages, often used to send data through the Post table one-way background program, in Flash, we can do this.

As we can see from TXT, or other files, the previous two items are the same as the original file address and the MC layer, except that the send using Post is used on the last option. In that case, all variables defined in Flash (and, of course, the corresponding layer in location definition, in this case, Level 0) can be referenced directly in the corresponding background program, as to how to refer to the method and the variable method of post in the form that handles HTML. If you can refer directly to PHP, the ASP uses Request.Form ("variable name") or reques.querystring ("variable name") to refer to the variable.

In contrast, you can use the Get method to obtain the corresponding variable from the ASP. (You can use either get or post when you actually use it)

After you know how to use this function, let's take a look at the following simple example:

Example one score query

The example is to read the data in Access and display it in Flash. This example has a total of three main files, database file Score.mdb, Flash file score.swf and ASP file score.asp.

The relationship between the three files is:

We use score.swf to make the query interface and pass the user input data to score.asp. And score.asp will receive the data and database Score.mdb data in the comparison, and the results back to score.swf display.

One is Access's database file Score.mdb, which has a score table with four fields:

Id,studentname (name), Coursename (subject), Scoremark (grade).

Now let's take a look at the process of making this example.

The first shadow frame, action is stop, and there is a text box for the user to enter the query field: INPUT1, Input2, INPUT3 (currently using only one), two buttons, one is OK, and the other is the Cancel button:

The action of the OK button is:

On (release) {
gotoAndPlay (2);
}

The action of the Cancel button is:

On (release) {
INPUT1 = "";
Input2 = "";
INPUT3 = "";
}

The action of the second Shadow frame is: Loadvariablesnum ("score.asp", 0, "get");

The action is to read the data in an Access database that matches the user's query criteria through an ASP file.

The action of the third Shadow frame is:

if (studentname ne "") {
gotoAndStop (9);
}

This means that if the studentname is not equal to a null value, it jumps to the nineth shadow frame, otherwise it will be performed (that is, play the next shadow frame).

第4-7个 Shadow frames have no action oh.

The action for the eighth Shadow frame is:

gotoAndPlay (3);

If you do not have the data, you will read it until you have read it and jump to the nineth frame.

So let's take a look at the ninth Shadow frame:

A total of three dynamic text boxes: Studentname, Coursename,scoremark

Data in the database that match the query criteria will be displayed among them.

There is also a "back" button whose action is:

On (release) {
gotoAndStop (1);
}

Well, let's see score.asp this file:

Dim RS, Conn ' defines two variables
Set RS = Server.CreateObject ("ADODB.") Recordset ")" defines RS as a Recordset object
Set Conn = Server.CreateObject ("ADODB. Connection ")" defines conn as Connection object
conn.connectionstring = "Driver={microsoft Access Driver (*.mdb)};
Dbq= "& Server.MapPath (" Score.mdb ")
Rs. Open "SELECT * from Score", Conn, 2, 3
' Open the database!
Rs. Find "Studentname = '" & UCase (Request.QueryString ("INPUT1")) & ""
' Find the data that matches the criteria
If RS. EOF Then ' If the data pointer is in the end
Response.Write "Studentname=not+found&coursename=not+found&scoremark=not+found"
' Just didn't find the data that matched the criteria.
Else
Response.Write "Studentname ="
& Server.URLEncode (RS ("Studentname"))
& "&coursename =" & Server.URLEncode (RS ("Coursename"))
& "&scoremark=" & Server.URLEncode (RS ("Scoremark"))
End If
Rs. Close
Set RS = Nothing
Conn.close
Set Conn = Nothing ' closes and empties a database object

Example two randomly producing words

From the database randomly extracted English words, training, this example a total of three major files, database file Word.mdb, Flash file word.swf and ASP file word.asp.

The relationship between these three documents is similar to the one in example.

One is Access's database file Word.mdb, which has a Word table with four fields:

Id,word,explain,symbol.

The first shadow frame, the action is stop, has a "Start" button, and its action is:

On (release) {
gotoAndPlay (2);
}
The action of the second Shadow frame is: Loadvariablesnum ("word.asp", 0, "get");
The action is to read the data in an Access database that matches the user's query criteria through an ASP file.
The action of the third Shadow frame is:
if (Explain NE "") {
gotoAndStop (9);
}

This means that if the explain is not equal to a null value, it jumps to the nineth shadow frame, otherwise it will be performed (that is, play the next shadow frame).

第4-7个 Shadow frames have no action oh.

The action for the eighth Shadow frame is:

gotoAndPlay (3);

If you do not have the data, you will read it until you have read it and jump to the nineth frame.

So let's take a look at the ninth Shadow frame:

A total of four text boxes: Word (display correct English words, dynamic), explain (Chinese explanation, dynamic), conclude (feedback correct/error, dynamic) Inputword (user input in English), the database in line with the query conditions of the data will be displayed in them!

OK button, the action of the OK button is:

On (release) {
if (Inputword ne Word) {
conclude = "Wrong!";
} else {
conclude = "Right!";
}
}

The "Surrender" button, without any action, simply hides the correct answer at the beginning and displays the following answer when clicked. There is also a "retry" button, and the action of the Retry button is:

On (release) {
gotoAndStop (3);
}

Well, let's see word.asp this file:

Dim RS, Conn ' defines two variables
Set RS = Server.CreateObject ("ADODB.") Recordset ")" defines RS as a Recordset object
Set Conn = Server.CreateObject ("ADODB. Connection ")" defines conn as Connection object
conn.connectionstring = "Driver={microsoft Access Driver (*.mdb)};
Dbq= "& Server.MapPath (" Word.mdb ")
Conn.Open
Rs. Open "SELECT COUNT (*) from word", Conn, 2, 3
Allnumber=rs.fields (0)
' Returns the total number of English words in the database
Rs. Close
RANDOMIZE
Keyword=int ((allnumber-1+1) *rnd)
' Take random numbers from
Rs. Open "SELECT * from Word", Conn, 2, 3
Rs. Find "ID =" & KeyWord
' Query ID equals the number of random words
If RS. EOF Then
Response.Write "Word=none&explain=none"
' Not found
Else
Response.Write "&word=" & Server.URLEncode (RS ("Word")) & "&explain=" & Server.URLEncode (RS (" Explain "))
' Find out after output? ' Not only do you have to use ' &word ' Otherwise you can't pass a value
End If
Rs. Close
Set RS = Nothing
Conn.close
Set Conn = Nothing ' closes and empties a database object



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.