Posted in Adobe, Flash
07/8 2006

AS2 :: FlashCookie Class

Goal: Create a simple way to incorporate SharedObjects into Flash-based forms.

class org.thesourcecode.utils.FlashCookie
{
   private var _mainTL:MovieClip;
   private var _cookie:SharedObject;
   private var _cookieName:String;
   private var _chips:Object;
 
   public function FlashCookie( newCookie:String,target:MovieClip )
   {
      this._cookieName = newCookie;
      _cookie = SharedObject.getLocal( _cookieName );
      _mainTL = target;
   }
 
   public function bakeCookie( obj:Object ):Void
   {
      var i:String;
      for (i in obj)
      {
         _cookie.data[ i ] = obj[ i ];
         _cookie.flush();
      }
   }
 
   public function getChip( str:String ):String
   {
      return _cookie.data[ str ];
   }
 
   public function getChips():Object
   {
      _chips = _cookie.data;
      return _chips;
   }
 
   public function getCookieName():String
   {
      return _cookieName;
   }
 
   public function checkCookie( prop:String, fields:Array )
   {
	   if (_cookie.data[prop] != undefined)
	   {
		   var i:Number;
		   for (i=0; i < fields.length; i++)
		   {
			   _mainTL[ fields[i] ].text = _cookie.data[ fields[i] ];
		   }
	   }
   }
 
   public function addChips( fields:Array )
   {
	   var i:Number;
	   for (i=0; i<fields.length; i++)
	   {
		   //trace( _mainTL[fields[i]].text );
		   _cookie.data[  fields[i] ] = _mainTL[ fields[i] ].text;
	   }
	   _cookie.flush();
   }
 
   public function eatCookie()
   {
	   _cookie.clear();
   }
 
}

Download the easy-install extension and sample files here.

Documentation can be found here.

This Post tags: ,

 

USER COMMENTS

Track comments via RSS 2.0 feed. Feel free to post the comment, or trackback from your web site.

Currently there are no comments related to article "AS2 :: FlashCookie Class".

Get Adobe Flash playerPlugin by wpburn.com wordpress themes