Interaction between Flash and Asp

Source: Internet
Author: User

1. Interaction between Flash and Asp

Flash communicates with Asp over Http. The request format is http: // ip address? Parameter 1 = value 1 & Parameter 2 = value 2

That is, add a question mark after the destination address and keep up with the parameter string. Separate the parameters with the Ampersand. For example:
Http://www.pcedu.com.cn/test.asp? Userid = guest & pwd = 123

In the preceding request, the target file of the request is.

The interaction between Flash and Asp is nothing more than constructing the above request string.

1. In Flash, the request string is constructed first, and then the LoadVariables () function can be used to send requests and parameters to the server. Let's take a closer look at the LoadVariables () function.

The standard function format is loadVariables ("url", level/"target" [, variables]).

In each parameter of the function, the url is the request string mentioned above. Level/"target" indicates the "level" or "target" of the returned value. Only one of the two levels can be specified. Variables is the request method. The value can be "Get" or "Post". Generally, Get is used for transmitting the parameter value in a short manner, and Post is used for transmitting the parameter value in a long manner, this parameter is optional. For example loadVariables ("http://www.pcedu.com.cn/guest.asp? Userid = guest & pwd = 123 ", 0," GET ") is a complete request.

2. In Asp, the parameters transmitted from Flash must be obtained first, which is the same as operating common HTML forms. The Request object is used, and its statement is:

Username = Request ("userid ")
Password = Request ("pwd ")

Userid and pwd are the parameter names sent from the Flash end. If they are the request strings in the previous step, the username value is guest and the pwd value is 123.
3. After processing the request on the server end and obtaining the required value, Asp sends the result to the Flash end. Like the Html language used in Asp, the Response object is used. The statement is:

Response. Write ("login = true & des = success ")

The value of 1 is login, the value is true, the value of 2 is des, and the value is success.

4. Obtain the value returned from the server on the Flash end, which is no different from the common variables in Flash. For example:
_ Root. gotoAndPlay (eval (login) indicates the frame to jump to the login value. However, it should be noted that the returned value can be used only after a request is sent for a period of time. Otherwise, the returned value is not returned, and errors are inevitable, and such errors are hard to be found, be careful when using it.

2. Interaction between Asp and databases

In Asp, ADO controls are generally used for interaction with databases. Its statement for reading the database is:

'Define a Connection object
Set conn = Server. CreateObject ("ADODB. Connection ")
'Use the Connection object to open the database. Here SQL server is opened, and the database address is 192.168.1.32.
'Database Username: zengyu, password: 123
Conn. open application ("Driver = {SQL Server}; SERVER = 192.168.1.32; DATABASE = test; UID = zengyu; PASSWORD = 123 ")
'Create A Recordset object
Set rstemp = Server. CreateObject ("ADODB. Recordset ")
'Construct an SQL statement
Sqltemp1 = "select * from UserInfo where userid = '" & strname & "' and password = '" & strpassword &"'"
'Query the database
Rstemp. open sqltemp1, conn, 1, 1
If not (rstemp. bof and rstemp. eof) then
Response. Write ("login = true ")
End if

Here, we only implement a simple query of the database. To learn more about Asp database operations, you can find Asp and database materials for further study.

Iii. Example-login implementation

Next we will create a simple instance, enter the user name and password on the Flash end, and query the database through Asp. If the user name and password are correct, we will jump to the login success interface, otherwise, the logon Failure page is displayed.

1. Create a new Flash, and create two text boxes and a Button in the scene, as shown in 2. The text box attribute 3 corresponding to the user name is shown in the text box attribute 4 corresponding to the password. Note the text type and variable name.
2. Create two other key frames, named "true" and "false" respectively, with the words "Login successful" and "Login Failed" displayed respectively.

3. Add the following statement in the Button's ActionScript, and change the IP address.

On (release ){
LoadVariables ("http: // 192.168.1.32/guest. asp? Userid = "add eval (_ root. userid) add" & pwd = "add eval (_ root. pwd), this," GET ");
Now = new Date ();
Begintime = now. getSeconds ();
While (true ){
Endt = new Date ();
Endtime = endt. getSeconds ();
If (endt-now> 2)
{
_ Root. gotoAndPlay (eval (login ));
}
}
}

4. Create a table named "userinfo" in the SQL Server database (the database type is not important, you can change the connection string, there are two fields: "Userid" and "Password.

5. Create a guest. asp file with the content

 

6. Deploy the Flash and Asp files to the IIS server, open the Flash file, and enter the login information to see the effect of the instance.

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.