Using ASP to manipulate Cookies in Flash

Source: Internet
Author: User
Tags contains
Cookie|cookies is necessary to set up and read cookies in Flash, for example, to provide Web site virtualization in Flash files.
Flash does not support direct settings and read cookies. Therefore, it is generally used JavaScript or ASP scripts settings and read Cookies. In addition to the other, the other good is that Flash does not have JavaScript function can still access cookies. Flash File Case
The following describes the Flash file can be set and read cookies, the file called ASP Scripts testcookies.aspsetcookies.aspAnd getcookies.aspCookies are accessed by the ASP from the browser.
The Flash file is tested to allow you to set the client's cookies and allow you to use the information stored in cookies, and the file can be read in cookies and present on the screen.
There are two files in the download: one is in English. FLA, the other file is in German. To translate. SWF is only German.

User interface


The user interface is divided into the following three parts to explain:

graphic: User interface in Flash

Step 1:


The user presses the ' START TEST ' button to accept cookies in the server's browser to see if the web's visitors ' browsers are available. The Status message will now accept cookies.

Step 2:


In this example cookies are accepted, Flash movie is executed to the second part and waits for the data to be stored in a cookie. Click the ' SEND DATA ' button and the information will be sent to the server.

Step 3:


In the end, server sends cookie data back to the Flash file and writes them into the text (text fields).

Flash file's Scripts


The Flash file is based on a standard procedure and is therefore not detailed.
Name ' SourceCode' Layers (layer) are important, including the code for the Flash file, and we're going to explain it now.

Diagram II: The time axis in Flash
Frame 1Set Variable: "Cookies" = "false" Stop

Variables ' Cookies' Initialized to String ' false' When the server does not return the Boolean value trueAnd false, you'll use ' false'。 But strings contain values " trueOr false, Flash waits for the button to activate the cookie test.
Frame 2, Label step1load Variables ("/testcookies.asp", 0)

File ' testcookies.asp' Be called and returned ' trueOr false' (Accept cookies or do not accept cookies).
Frame10 If (Cookie eq "true") Set Variable: "CookieTest" = "Cookie can be set" Stop Else set Variable: "CookieTest" = " Cookies not allowed. Please enable. " Go to and Stop (' nocookies ') end If

The Frame 10 will show different messages according to the test results.
If you don't accept Cookies,flash, you'll jump to the tag. nocookies', stop there and don't accept any input except for another cookie test. In ifData cookies eq "true"With the citation set, because the server and the real return of the Boolean value trueOr false, but the string itself can be tested on the horse itself. At the same time note that the comparison of strings must be to use ' eq' And not ' ='。
The ' Stop ' command allows Flash to wait for the ' SEND DATA ' button click event. Sending cookie data to the server will look like this:
Frame11, Label step2load Variables ("/setcookies.asp?cookiename=" &name& "&" & "Cookiemail=" & email& "&" & "Cookietelephone=" &telephone, 0)

In this script, please ask the string (query string) containing the user input data to be sent to the file. setcookies.asp'。 For the composition of the string, please refer to the article ' Data Exchange between ASP and Flash ' (in German only).
Frame19, Label step3load Variables ("/getcookies.asp", 0)

The ASP's information from cookies is downloaded into the Flash file.
Frame 28Stop

After the short line animation, the downloaded data is presented in the Text field (text fields).
Frame, Label Nocookiesstop

If you do not allow any of the cookies,flash axes to be placed into this frame in frame 10, the user will have the opportunity to perform additional tests. Scripts of ASP files
These three files testcookies.aspsetcookies.aspAnd getcookies.aspis executed by the Flash call: Check to see if the browser accepts cookies ( testcookies.asp), set Cookies ( setcookies.asp), read cookies ( getcookies.asp)。

Check to see if the browser accepts cookies


File testcookies.asp Check to see if the browser allows cookies. This technique is the same technique as the "simple Browser Cookie Test" (German only) in this article. The script used here is as follows:
<%strtest = Request.QueryString ("CookieTest") If UCase (strtest) <> UCase ("true") Then ' a call ' Set session V Ariable session ("__flashcookietest") = True ' Redirect with querystring strURL = Request.ServerVariables ("Script_name") s trquerystring = "? Cookietest=true "Response.Redirect (strURL & strquerystring) Response.endelse ' Redirect already happened ' Check whet Her 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 are empty ' Thus browser ' does not accept Co Okies strout = "Cookies=false" End IfEnd If ' Output to Flash:Response.Write (strout)%>

Simply, this script set a session variable, perform the jump (redirect) to itself, and then check whether the value is set in the session variable. To keep the value still saved, the browser must already accept the session cookie for Internet information Server (IIS) and then send it to the browser by ASP. This means that the browser accepts cookies when the value of this session variable still exists after the jump (redirect).
If the browser accepts cookies, the file will return text ' cookies=true' or ' not accepted ', it is returned ' Cookies=false'。
When Flash by command Load VariablesTo call the file. testcookies.asp, the ASP file will return the string " cookies=trueOr Cookies=false"To the Flash file, and then set the variable in Flash. CookiesWhy trueOr false" 。

Set Cookies


Cookies can be easily used in ASP Response.CookiesCollection settings. In our case, this Flash file is called a file. setcookies.asp, and then send the QueryString cookies (names and values) to ASP Script.
The ASP Script reads all the values from the QueryString collection, by Respon



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.