Use cookies in flash via ASP

Source: Internet
Author: User
Cookie written By:günter Hoffellner
Translated By:bernhard Spuida
The published:9/8/2000

Setting or reading cookies in Flash could necessary for example to extend the personalization of a Web
Site to the Flash file.

Flash does not support direct setting and reading of cookies. Thus, you either have to take the often
Published detour of using JavaScript or you just the use ASP scripts to set and read cookies. This has among
Other things the advantage so Flash can access cookies even when JavaScript is disabled.

The Flash File
In the following, the Flash file which can read and set cookies at the client is described. The file calls
The ASP Scripts testcookies.asp, setcookies.asp and getcookies.asp to gain access to the browser ' s cookies
Via ASP.

The Flash file tests for the permission to set client side cookies and allows entering
stored in a cookie. The file also reads the cookie content and displays it on screen.

There are two files in the Download:one. Fla in 中文版, and a second one in German. The compiled. SWF is
Available in German.

The User Interface
The user interface is divided to three parts which are described in the following sections.


Figure 1:user interface in Flash

Step 1:
The user clicks the ' START TEST ' button to trigger the "test on the" server to determine whether the browser
The page visitor accepts cookies. The status message indicates whether the browser accepts cookies or
Not.

Step 2:
In the case of the cookie being accepted, the Flash movie runs on to the second part and waits for the
Saved in a cookie. With a click on the ' SEND Data ' button, the "data is transmitted" to the server.

Step 3:
In the last part, the server passes the cookies data back to the Flash file where they are written into the
Text fields.

The Scripts of the Flash File
The graphic part of the Flash file was built according to standard procedure and isn't described in detail
For this reason.

The layer with the name ' SourceCode ' are important, as this contains the source code of the Flash file. We
Would go to the details of this now.


Figure 2:time Line in Flash


Frame 1
Set Variable: "Cookies" = "false"
Stop


The variable ' cookie ' is initialised with the string ' false '. ' false ' is used as the server does not
Return the Boolean values true and 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 ' (cookie accepted-cookies not
Accepted).


Frame10
If (Cookie 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 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 won't accept any
Input but another cookie test. In the If-condition cookie eq "true" was set in quotes as the server does
Not really return the Boolean to true or false, but a string which is immediately tested as such.
Also 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 are 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 was loaded into the Flash file.
Frame 28
Stop


The



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.