通过ASP在Flash中妙用Cookie

cookie

Written by: Günter Hoffellner
Translated by: Bernhard Spuida
First published: 9/8/2000

Setting or reading cookies in Flash may be 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 use ASP scripts to set and read cookies. This has among
other things the advantage that 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 data that is to be
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 English, and a second one in German. The compiled .swf is
available in German only.

The User Interface
The user interface is divided into 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
of the page visitor accepts cookies. The status message indicates whether the browser accepts cookies or
not.

Step 2:
In the case of cookies being accepted, the Flash movie runs on to the second part and waits for data to be
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 cookie 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 is built according to standard procedure and is not described in detail
for this reason.

The layer with the name 'Sourcecode' is important, as this contains the source code of the Flash file. We
will go into the details of this now.

Figure 2: Time line in Flash

//Frame 1
Set Variable: "cookies" = "false"
stop

The variable 'cookies' 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' (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

时间: 2024-12-10 23:29:26

通过ASP在Flash中妙用Cookie的相关文章

在 Flash 中使用 ASP 操控 Cookies

cookie|cookies 在 Flash 中設定以及讀取 cookies 是有必要的,例如可以在 Flash 檔案中提供網站個人化. Flash 不支援直接的設定以及讀取 cookies.因此,一般就是使用 JavaScript 或是 ASP scripts 設定以及讀取 Cookies.除了別的以外,另一好處是 Flash 即時是沒有 JavaScript 功能下仍能存取 cookies. Flash 檔案在下面描述了 Flash 檔案可以設定以及讀取 cookies,該檔案呼叫 ASP

在在Flash中使用ASP技术

在Flash中使用ASP需要的条件: 1.你的ISP的server必须支持Active Server Pages并且最好支持数据库 2.你应该要安装Flash mx 3.需要你对ASP有初步的了解OK,下面具体介绍怎么使用: 第一步要做的是建立数据库: 数据库结构: 例子中使用Access数据库,表名为tblStaff,有三个字段:strID (自动编号),strKnownAs(Text),strSurname (Text). 这是一个用来示范用户名的数据库,随便加些数据吧. 第二步就是建立一个

在Flash中使用ASP技术

数据库结构:第一步:建立数据库.例子中使用Access数据库,表名为tblStaff,有三个字段:strID (自动编号), strKnownAs(Text), strSurname (Text).这是一个用来示范用户名的数据库,随便加些数据吧. 第二步:建立一个 Flash 4 的动画: 步骤如下:1)建立三个text field,它们是用来显示数据用的. 2)把第一个text field的name设置为Input,它是用来接收输入数据的. 3)另外两个text field分别命名为Known

在ASP.NET应用中插入flash动画

asp.net|flash动画|插入 学ASP.NET的同学可能还在疑问是否能播放动画,其实在ASP.NET中的swf格式的播放和在html中是一样的你只需要在ASP.NET中的界面中的<html>和</html>中插入下边的代码就行了. <div align="center"> <!----------------------以下代码用来显示flash-------------------------> <object class

以前收集的一些资料---在Flash中使用ASP技术

                          在Flash中使用ASP技术   在Flash中使用ASP需要的条件:1.你的ISP的server必须支持Active Server Pages并且最好支持数据库2.你应该要安装Flash 43.需要你对ASP有初步的了解OK,下面具体介绍怎么使用:数据库结构:第一步要做的是建立数据库.例子中使用Access数据库,表名为tblStaff    有三个字段:strID (自动编号), strKnownAs(Text),strSurname (T

【ASP.NET Web API教程】5.5 ASP.NET Web API中的HTTP Cookie

原文:[ASP.NET Web API教程]5.5 ASP.NET Web API中的HTTP Cookie 5.5 HTTP Cookies in ASP.NET Web API 5.5 ASP.NET Web API中的HTTP Cookie 本文引自:http://www.asp.net/web-api/overview/working-with-http/http-cookies By Mike Wasson|September 17, 2012 作者:Mike Wasson | 日期:

在FLASH中调用ASP

在Flash中使用ASP需要的条件:1.你的ISP的server必须支持Active Server Pages并且最好支持数据库2.你应该要安装Flash 43.需要你对ASP有初步的了解OK,下面具体介绍怎么使用:数据库结构:第一步要做的是建立数据库.例子中使用Access数据库,表名为tblStaff有三个字段:strID (自动编号), strKnownAs(Text),strSurname (Text).这是一个用来示范用户名的数据库,随便加些数据把.第二步就是建立一个Flash 4的动

在Flash中调用Html的层

本教程需要大家有一些关于HTML, CSS, Flash, JavaScript 和ASP的基础知识     用Html文本与Flash一起来制作动画是一个很好的方式. 它非常的简单, 而且容易上手,只需要使用ActionScript中的getURL()脚本就可以了,比你能想象到的任何其他编成语言(例如JavaScript)都更方便,功能也更强大.     请看下面这个情节: 在一个特殊工程中,设计师需要Flash 动画运行于页面的顶端,然后在Flash播放后,再显示文本.你可以在Flash中做

Flash中oop的设计模式

设计 有人问我flash的as应该怎么写,我可以很负责任地告诉他,想怎么写就怎么写,因为as以及flash内部的构成模式决定了它的高度自由化.理论上来说,用按钮的on事件,加上stop(),play(),gotoAndStop(),gotoAndPlay(),就可以实现一个flash里大部分的逻辑关系,而且源代码简单易懂.但是大多数人不会这么做,是因为这种方法实在太让人敬佩.稍有常识的程序员都会知道面对对象与面对过程的区别.Flash的编程虽然只是以脚本的形式出现,并且还很不完善,比如,没有多继