Flash cookies mainly use the jsonobject class. The advantage of flash cookies is that users are not easy to delete and can write a large amount of data, but the disadvantage is that if you shield flash, it will be over.
The main class mainly provides external js methods.
Purpose: You can set swf to 1x1 pixel to hide it. Write Data Using js.
Cookie type
The Code is as follows:
Package com. tools {
Import flash.net. Export dobject;
//
Public class Cookie {
Private var _ $ so: Export dobject;
///
Function Cookie (){
Init ();
}
Private function init (): void {
}
//--------------------------------------------//
Public function setCookie (key: String, val: String, name: String = "sina_cookie"): void {
// Trace ("setCookie ");
_ $ So = export dobject. getLocal (name );
// _ $ So. data ["old"] = "26 ";
_ $ So. data [key] = val;
}
Public function getCookie (key: String, name: String = "sina_cookie"): String {
_ $ So = export dobject. getLocal (name );
// Trace ("key:" + key + "-- data:" + _ $ so. data. key)
If (_ $ so. size> 0 & _ $ so. data [key]) {
Return _ $ so. data [key];
} Else {
Return null;
}
}
Public Function clearkey (key: String, name: String = "sina_cookie"): void {
_ $ So = export dobject. getlocal (name );
_ $ So. Data [Key] = NULL;
}
Public Function clearcookie (): void {
_ $ So. Clear ();
}
Public Function flush (): void {
_ $ So. Flush ();
}
} // End class
}
Implementation class (main class)
Package com. Sina. testcookie {
Import flash. display. Sprite;
Import flash. External. externalinterface;
Import com. Tools. Cookie;
//
Public class maincookie extends sprite {
Private VaR _ $ CO: cookie;
//
Function maincookie (){
Init ();
}
Private function Init (): void {
_ $ CO = new cookie ();
// ------ Test ---------
Setcookie ("name", "Antz ");
// Flush ();
// Clearcookie ();
// Clearkey ("name ")
// Trace (getcookie ("old "))
Addcallback ();
}
Private function addCallBack (): void {
ExternalInterface. addCallback ("setCookie", setCookie );
ExternalInterface. addCallback ("getCookie", getCookie );
ExternalInterface. addCallback ("flush", flush );
ExternalInterface. addCallback ("clearCookie", clearCookie );
ExternalInterface. addCallback ("clearKey", clearKey );
}
Private function setCookie (key: String, value: String ){
_ $ Co. setCookie (key, value );
// Return getCookie (key)
}
Private function getCookie (key: String): String {
Var val = _ $ co. getCookie (key );
Return val;
}
Private function flush (): void {
_ $ Co. flush ();
}
Private function clearCookie (): void {
_ $ Co. clearCookie ();
}
Private function clearKey (key: String): void {
_ $ Co. clearKey (key)
}
} // End class;
}