ASP and Flash combined development of the basic course of application

Source: Internet
Author: User
Tags date format object end eval sql variables string

1, the interaction between Flash and ASP
2, ASP and the interaction between the database
3, Asp+flash Development Source code example-the realization of landing

Flash's functionality is already very powerful and can be combined with other server-side languages to make Web sites that fit the Web applications now. A typical model is the combination of flash and ASP. Its architecture is shown in Figure 1.

Figure 01
The above structure can be seen as the three layer, flash is a layer, ASP is a layer, the database is a layer. Flash and ASP a little understanding of the people, as long as the layer and layer to deal with the interaction between the use of Flash and ASP is never difficult.

   first, let's take a look at the interaction between Flash and ASP

Flash and ASP communication is the HTTP protocol, its request format is HTTP://IP address? parameter 1= value 1& parameter 2= value 2

That is, after the destination address with a question mark, followed by the parameter string, between the parameters with the "&" lattice open. Such as:
Http://www.pcedu.com.cn/test.asp?userid=guest&pwd=123

In the above request, the requested destination file is: http://www.pcedu.com.cn/test.asp, the first parameter named UserID, the value is guest, the second parameter is named PWD, and the value is 123.

The interaction between flash and ASP is nothing more than constructing the request string above.

1, in Flash, the first construct the string of the request, and then use the function Loadvariables (), you can send requests and parameters to the server side. Let's take a detailed look at the Loadvariables () function.

The standard format for a function is loadvariables ("url", level/"target" [, variables])

In each parameter of the function, the URL is the request string mentioned above. level/"Target" is the "level" or "target" of the return value, and only one of these two can be specified. The variables is the way of the request, the value can be "get" or "Post", and the general take is used for a relatively short transfer of the parameter value, which is optional when the Post is used for a lengthy transfer of the parameter values. For example, Loadvariables ("http://www.pcedu.com.cn/guest.asp?userid=guest&pwd=123", 0, "get") is a complete request.

2, in the ASP, first to obtain from the flash end of the parameter, which is the same as the operation of ordinary HTML form. are used by the request object, and the statements are:

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

UserID and PWD are the names of the parameters sent from the flash end, and if the request string in the previous step, the value of username is Guest,pwd 123.

3, the server end of processing requests, to obtain the required value, the ASP to the flash end to send results, follow the ASP in the operation of HTML language, are used response object, the statement is:

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

Its return value of 1 is named login, the value is true, and the return value of 2 is named Des, and the value is success.

4, in the flash end of the return from the server side of the value, and operation of Flash in the ordinary variables are no different. Such as:
_root.gotoandplay (eval (login)) represents the frame that jumps to the value of login. But note that after sending a request for a period of time, to use the return value, otherwise it is not returned to the value of the error is inevitable, and this kind of error is difficult to find, use the time to be more careful.

   ii. interaction between ASP and the database

The interaction between ASP and database is usually with ADO control. The statement that reads the database is:

' Define a Connection object
Set Conn=server.createobject ("ADODB. Connection ")
' Open the database with the Connection object, where SQL Server is open, and the database address is 192.168.1.32
' Database username is Zengyu, password is 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& ""
' Querying the Database
Rstemp.open Sqltemp1,conn, 1, 1
If not (RSTEMP.BOF and rstemp.eof) then
Response.Write ("Login=true")
End If

Here to achieve a simple query database, to understand the ASP operation of the database more detailed things, you can find the ASP and database information in-depth study.

   Iii. Example-the realization of landing

Below we will make a simple example, in the Flash input username and password, through the ASP query database, if the user name and password is correct, jump to login successful interface, otherwise jump to login failure interface.

1, create a new flash, in the scene to make two text boxes and a button, as shown in Figure 2. Where the user name corresponds to the text box properties as shown in Figure 3, the text box properties corresponding to the password are shown in Figure 4. Note the text type and variable name.

Figure 02

Figure 03

Figure 04
2, create another two keyframes, named "True" and "false" respectively, and display the words "landing success" and "Landing failed."

3, add the following statement in the ActionScript of the button, and notice that the IP address is changed.

On (release) {
Loadvariables ("http://192.168.1.32/guest.asp?userid=" add eval (_root.userid) Add "&pwd=" Add eval (_root.pwd), This, the "get");
now = new Date ();
BeginTime = Now.getseconds ();
while (true) {
Endt = new Date ();
Endtime = Endt.getseconds ();
if (Endt-now > 2)
{
_root.gotoandplay (eval (login));
}
}
}

4, in the SQL Server database (the type of the database is not important, change the connection string can be), create a table named "UserInfo", which has "Userid" and "Password" two fields.

5, the establishment of a guest.asp file, the contents of the document
-->

6, the Flash file and ASP files deployed to the IIS server, and then open the Flash file, enter the login information can see the effect of the example.

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.