当我关闭窗口饼干正在弹性销毁

时间:2010-05-25 11:06:47

标签: flex flex3

我使用外部接口在应用程序的客户端存储cookie。就像我在html中创建了一个cookie,我使用外部接口在flex中使用这些方法。当我使用cookie显示时,我在cookie中保存用户名,我已经部署在服务器中,我像http://localhost/[Path]/index.html.in那样运行这个html我是嵌入式swf文件,我已经在html JavaScript中保存了cookie,现在如果我打开这个url cookie正在保存,如果我打开一个新的窗口,什么cookie是一个凸起的,它是从开始加载。用于cookie保存我在flex中使用此代码:`package Name {

import flash.external.ExternalInterface; 

/** 
 * The Cookie class provides a simple way to create or access 
 * cookies in the embedding HTML document of the application. 
 *  
 */ 
public class Cookies { 

    /** 
     * Flag if the class was properly initialized. 
     */ 
    private static var _initialized:Boolean = false; 

    /** 
     * Name of the cookie. 
     */ 
    private var _name:String; 

    /** 
     * Contents of the cookie. 
     */ 
    private var _value:String; 

    /** 
     * Flag indicating if a cookie was just created. It is <code>true</code> 
     * when the cookie did not exist before and <code>false</code> otherwise. 
     */ 
    private var _isNew:Boolean; 

    /** 
     * Name of the external javascript function used for getting 
     * cookie information. 
     */ 
    private static const GET_COOKIE:String = "cookieGetCookie"; 

    /** 
     * Name of the external javascript function used for setting 
     * cookie information. 
     */ 
    private static const SET_COOKIE:String = "cookieSetCookie"; 

    /** 
     * Javascript code to define the GET_COOKIE function. 
     */ 
    private static var FUNCTION_GET_COOKIE:String = 
            "function () { " + 
                    "if (document." + GET_COOKIE + " == null) {" + 
                            GET_COOKIE + " = function (name) { " +  
                                    "if (document.cookie) {" +  
                                            "cookies = document.cookie.split('; ');" +  
                                            "for (i = 0; i < cookies.length; i++) {" +  
                                                    "param = cookies[i].split('=', 2);" +  
                                                    "if (decodeURIComponent(param[0]) == name) {" +  
                                                            "value = decodeURIComponent(param[1]);" +  
                                                            "return value;" +  
                                                    "}" +  
                                            "}" +  
                                    "}" +  
                                    "return null;" +  
                            "};" + 
                    "}" + 
            "}"; 

    /** 
     * Javascript code to define the SET_COOKIE function. 
     */ 
    private static var FUNCTION_SET_COOKIE:String = 
            "function () { " + 
                    "if (document." + SET_COOKIE + " == null) {" + 
                            SET_COOKIE + " = function (name, value) { " +  
                                    "document.cookie = name + '=' + value;" +  
                            "};" + 
                    "}" + 
            "}"; 

    /** 
     * Initializes the class by injecting javascript code into 
     * the embedding document. If the class was already initialized 
     * before, this method does nothing. 
     */ 
    private static function initialize():void { 
            if (Cookies._initialized) { 
                    return; 
            } 

            if (!ExternalInterface.available) { 
                    throw new Error("ExternalInterface is not available in this container. Internet Explorer ActiveX, Firefox, Mozilla 1.7.5 and greater, or other browsers that support NPRuntime are required."); 
            } 

            // Add functions to DOM if they aren't already there 
            ExternalInterface.call(FUNCTION_GET_COOKIE); 
            ExternalInterface.call(FUNCTION_SET_COOKIE); 

            Cookies._initialized = true; 
    } 

    /** 
     * Creates a new Cookie object. If a cookie with the specified 
     * name already exists, the existing value is used. Otherwise 
     * a new cookie is created as soon as a value is assigned to it. 
     *  
     * @param name The name of the cookie 
     */ 
    public function Cookies(name:String) { 
            Cookies.initialize(); 

            this._name = name; 
            this._value = ExternalInterface.call(GET_COOKIE, name) as String; 

            this._isNew = this._value == null; 
    } 

    /** 
     * The name of the cookie. 
     */ 
    public function get name():String { 
            return this._name; 
    } 

    /** 
     * The value of the cookie. If it is a new cookie, it is not 
     * made persistent until a value is assigned to it. 
     */ 
    public function get value():String { 
            return this._value; 
    } 

    /** 
     * @private 
     */ 
    public function set value(value:String):void { 
            this._value = value; 

            ExternalInterface.call(SET_COOKIE, this._name, this._value); 
    } 

    /** 
     * The <code>isNew</code> property indicates if the cookie 
     * already exists or not. 
     */ 
    public function get isNew():Boolean { 
            return this._isNew; 
    } 
} 

}

我正在使用像var anotherCookie:Cookies = new Cookies("username"); anotherCookie.value=[Textinput].text;这样的cookie。我是否需要在新窗口中使用保存cookie?请帮助我提前谢谢。

1 个答案:

答案 0 :(得分:0)

默认情况下,浏览器会在当前会话结束时删除Cookie,例如当他们关闭浏览器时。您可以将“过期”日期设置为某个远期日期,以便它可以暂停一段时间。请注意,如果他们有某些类型的防病毒程序,它也可能会删除cookie。