asp学习网: 首页 >> 杂项 >> asp与flash >> ASP/Flash/Cookie

ASP/Flash/Cookie

r. The complete ASP script consists of only three lines:


<%
For each item in Request.QueryString
Response.Cookies(item) = Request.Querystring(item)
Next
%>


Reading Cookies
Reading the cookies and writing them to the Flash File is about as easy as setting the cookies. When the
Flash file calls the file getcookies.asp, it returns all the names and values of the cookies as URL-
encoded text. This way, the values of the cookes are written to variables of the same names in Flash when
Flash calls the filegetcookies.asp.

The ASP file getcookies.asp is as follows:


<%
For each cookie in Request.Cookies
strOut = strOut & Server.URLEncode(cookie) & "="
strOut = strOut & Server.URLEncode(Request.Cookies(cookie))
strOut = strOut & "&"
Next
Response.Write strOut
%>


Conclusion
The Flash based part of this article was created using Flash 4. The systematics are the same for the newly
published Version 5 of the Macromedia software.

The ASP part runs on IIS 4.0 as well as on IIS 5.0 and with slight modifications also under ASP+.

After having described setting and reading of cookies in Flash in conjunction with ASP in this article,
one of the next articles will further develop this by using the present base for simple personalization of
a Flash file using cookies.
d false, but a string with the value of "true" or "false". Flash waits
for the button click for starting the cookie test.


//Frame 2, Label step1
Load Variables ("/testcookies.asp", 0)


The file testcookies.asp is called and returns true or false (Cookies accepted - Cookies not
accepted).


//Frame10
If (cookies eq "true")
Set Variable: "cookietest" = "Cookies can be set"
Stop
Else
Set Variable: "cookietest" = "Cookies not allowed. Please enable."
Go to and Stop ("nocookies")
End If


In Frame 10 a different message is displayed in the status field depending on the result of the cookie
test.

If cookies are not accepted, Flash jumps to the label nocookies, stops there and will not accept any
input but another cookie test. In the if-condition cookies eq "true" is set in quotes as the server does
not really return the boolean values of true or false, but a string which is immediately tested as such.
Also note that the string comparison requires eq instead of =.

The stop command forces Flash to wait for a click event of the SEND DATA button. Sending the cookie
data to the server happens as follows:


//Frame11, Label step2
Load Variables ("/setcookies.asp?cookiename="&name&"&"&
"cookiemail="&email&"&"&"cookietelephone="&telephone, 0)


In this script, a query string containing the user entries is sent to the file setcookies.asp. For the
composition of the query string, refer to the article Data Exchange between ASP and Flash (German only).


//Frame19, Label step3
Load Variables ("/getcookies.asp", 0)

The data read from a cookie by ASP is loaded into the Flash file.
//Frame 28
Stop


The loaded data is displayed in the text fields after a short animation of a line.


//Frame 35, Label nocookies
stop


If the test in frame 10 determines that no cookies are allowed, the Flash time line branches to this frame
and the user has the opportunity to perform another test.

The Scripts of the ASP files
The 3 files testcookies.asp, setcookies.asp and getcookies.asp are called by Flash for the following
actions: Checking whether the browser accepts cookies (testcookies.asp), setting cookies (setookies.asp),
reading cookies(getcookies.asp).

Checking whether the browser accepts cookies
The file testcookies.asp checks whether the browser permits cookies. The technique is the same as in the
article "Simple Browser Cookie Test" (German only). The variation of this script used here is as follows:


<%
strTest = Request.QueryString("CookieTest")
If UCase(strTest) <> Ucase("true") Then
First call
Set session variable
Session("__FlashCookieTest") = True
Redirect with QueryString
strURL = Request.ServerVariables("SCRIPT_NAME")
strQueryString = "?CookieTest=true"
Response.Redirect(strURL & strQueryString)
Response.End
Else
Redirect already happened
Check whether the session variable contains the value
If Session("__FlashCookieTest") = True Then
Session variable contains value
Thus browser accepts cookies
strOut = "Cookies=true"
Else
Session variable is empty
Thus browser does not accept cookies
strOut = "Cookies=false"
End If
End If
Output to Flash:
Response.Write(strOut)
%>


Simply put, the script sets a session variable, performs a redirect onto itself and then checks whether
the value still is set in the session variable. For this value to stay saved, the browser must have
accepted the session cookie of the Internet Information Server (IIS) which is automatically sent to the
browser by ASP. This means that the browser accepts cookies when the value in the session variable is
still present after a redirect.

The file returns the text Cookies=true if the browser accepts cookies or Cookies=false if the browser
does not accept cookies.

When Flash calls the file testcookies.asp via the Flash command Load Variables, the ASP file returns
either the string "Cookies=true" or "Cookies=false" to the Flash file which automatically sets the
variable Cookies to "true" or "false" in Flash.

Setting Cookies
In ASP, cookies can be set easily using the Response.Cookies collection. In our example, the Flash file
calls the file setcookies.asp and passes the variables for the cookies (names and values) in the
Querystring to the ASP Script.

The ASP Script reads all values out of the Querystring collection sends the corresponding cookies via
Response.Cookies to the brows

<%
For each item in Request.QueryString
Response.Cookies(item) = Request.Querystring(item)
Next
%>


Reading Cookies
Reading the cookies and writing them to the Flash File is about as easy as setting the cookies. When the
Flash file calls the file getcookies.asp, it returns all the names and values of the cookies as URL-
encoded text. This way, the values of the cookes are written to variables of the same names in Flash when
Flash calls the filegetcookies.asp.

The ASP file getcookies.asp is as follows:


<%
For each cookie in Request.Cookies
strOut = strOut & Server.URLEncode(cookie) & "="
strOut = strOut & Server.URLEncode(Request.Cookies(cookie))
strOut = strOut & "&"
Next
Response.Write strOut
%>


Conclusion
The Flash based part of this article was created using Flash 4. The systematics are the same for the newly
published Version 5 of the Macromedia software.

The ASP part runs on IIS 4.0 as well as on IIS 5.0 and with slight modifications also under ASP+.

After having described setting and reading of cookies in Flash in conjunction with ASP in this article,
one of the next articles will further develop this by using the present base for simple personalization of
a Flash file using cookies.

from:asp学习网/title:ASP/Flash/Cookie/ time:2006-12-18 21:30:18

本文主题,flash,ASP

ASP做网页时需要注意的一些问题

asp当中判断函数一览

asp入门者手册

用ASP输出Word、Excel文件

ASP读取XML

在将 Response.buffer(在 ASP 中)设置为 False 时 TCP/IP 连接中断

查询实际存在的 ASP 页时,出现“页找不到”的404错误

针对L-Blog(asp)的TrackBack Spam一点优化

asp教程 ©2006-2007 aspxuexi.com | 关于站点 | 版权隐私 | 站内搜索
复制或者翻版 请于夜间进行