Flash read/write cookie

Source: Internet
Author: User

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;
}

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.