The Source Code of ActionScript 3 Cookie class
来源:互联网 发布:疯狂java培训怎么样 编辑:程序博客网 时间:2024/04/28 04:06
D0The Source Code of Actionscrīpt 3 Cookie class–Enables You to Read, Write, and Edit Shared Objects on the User’s Hard Disk
Have you ever wanted to store persistent information in your Flash movies, save login information, shopping cart data, user preferences, even complex objects like arrays? If you have purchased “Flash Extension”, simply import the cookie class and copy the source code like following:
- import com.communitymx.Cookie;
- var myCookie:Cookie = new Cookie(”yoursite”);
- // user info
- myCookie.username = “nttlib”;
- myCookie.password = “abcdefg”;
- myCookie.save();
- // retrieve cookie info
- trace(myCookie.username); // result: nttlib
- trace(myCookie.password); // result: abcdefg
But…Maybe you have noticed the word “purchased”–yes, it is not free! The following is a free, similar above cookie class, using it you can set cookies in flash to remember a user’s music preference now.
Download: cookie.as
- package com.nttlib.util {
- import flash.net.SharedObject;
- public class Cookie {
- private var _time:uint;
- private var _name:String;
- private var _so:SharedObject;
- public function Cookie(name:String = "nttlib", timeOut:uint=3600) {
- _name = name;
- _time = timeOut;
- _so = SharedObject.getLocal(name, "/" );
- }
- // clear when timeout;
- public function clearTimeOut():void {
- var obj:* = _so.data.cookie;
- if(obj == undefined){
- return;
- }
- for(var key in obj){
- if(obj[key] == undefined || obj[key].time == undefined || isTimeOut(obj[key].time)){
- delete obj[key];
- }
- }
- _so.data.cookie = obj;
- _so.flush();
- }
- // check timeout
- private function isTimeOut(time:uint):Boolean {
- var today:Date = new Date();
- return time + _time * 1000 < today.getTime();
- }
- // get timeout;
- public function getTimeOut():uint {
- return _time;
- }
- // get cookie name;
- public function getName():String {
- return _name;
- }
- // clear all Cookie value;
- public function clear():void {
- _so.clear();
- }
- // add Cookie item( key-value )
- public function put(key:String, value:*):void {
- var today:Date = new Date();
- key = "key_"+key;
- value.time = today.getTime();
- if(_so.data.cookie == undefined){
- var obj:Object = {};
- obj[key] = value;
- _so.data.cookie = obj;
- }else{
- _so.data.cookie[key] = value;
- }
- _so.flush();
- }
- // remove Cookie item by key;
- public function remove(key:String):void {
- if (isExist(key)) {
- delete _so.data.cookie["key_" + key];
- _so.flush();
- }
- }
- // get Cookie item value by key;
- public function get(key:String):Object{
- return isExist(key)?_so.data.cookie["key_"+key]:null;
- }
- // check Cookie item exist;
- public function isExist(key:String):Boolean{
- key = "key_" + key;
- return _so.data.cookie != undefined && _so.data.cookie[key] != undefined;
- }
- }
- }
Cheers!
(from:http://ntt.cc/2008/07/13/the-source-code-of-actionscrīpt-3-cookie-class-enables-you-to-read-write-and-edit-shared-objects-on-the-user-hard-disk.html)
- The Source Code of ActionScript 3 Cookie class
- The source code of the Account class of the famous IM app
- The source code of the Receiver class of the famous IM app
- The source code of the SmsReceiver class of the famous IM app
- The source code of the BootCompletedReceiver class of the famous IM app
- java source code reverse class diagram of uml,tool
- How to find the source code of the special command?
- The ActionScript code generation target
- The Logbook of Qt Source Code Reading(1)
- The Study of Tomcat Source Code -- Part I
- The study of Tomcat Source Code -- Party II
- Chapter 1 A Guided Tour Of The MySQL Source Code
- Source Code of exe2com.
- Source Code of exe2com
- Source code of CIH
- Study of Source code
- Source code of ZMRP_VSS_CLEANUP
- source code of CV
- SQL UNIQUE 约束介绍
- SDHC 读写速度问题...
- spring2.0 和spring2.5包的变化
- memcpy() 和 memmove() 有什么区别?
- APR - freeswitch 的基石
- The Source Code of ActionScript 3 Cookie class
- 低调做人,你会一次比一次稳健;高调做事,你会一次比一次优秀!(偷来的自己留着学习)
- php define() 处理同名变量不能覆盖
- 嵌入式开发推荐书目
- 我發現。。。
- 热血三国
- 经典Linux书籍虾子啊
- javascript 评估用户输入密码的强度
- 用Div、CSS、JavaScript编写的Tab选项卡源代码,兼容所有浏览器