• About
  • Verse
  • Code
  • Sketch
  • Pix
  • Blog
Donline: The Personal Blog of Don Citarella

Flash Cookies

Ever want to be able to reference personalized information each time a user visits your Flash? Before Flash MX, you needed to use PHP cookies. But Macromedia/Adobe created Flash Cookies called SharedObjects to make this easier for you. I’m not kidding! It’s like two lines of code to save and retrieve locally-stored data each time a user browses the site.

Case and point, try entering your name and age to the Flash below. Then, click “Store” and either click the “Refresh” button, refresh your browser or hit F5.

This Flash movie cannot load. You are viewing this because:

  1. You have no Flash Plug-In (Click here to download)

2. Your Flash Plug-in is older than the necessary version required to play this movie (Click here to reload the movie and click “Yes” when asked to upgrade your plug-in.)


That data is stored as a SharedObject in your Flash Plug-in directory on your local computer. Even if you close the browser and re-open it, that data remains for you. This is especially helpful if you’ve created a game or chat client or application that requires this basic data each time a user accesses the site. And while it’s mildy-invasive, it’s pretty similar to the same process most sites use for storing information locally through PHP.

By default, the player enables you to store 100kb of data for each domain. Should you try to store more than that, the Adobe Flash Player settings dialogue box will pop-up over your movie to ask the user to increase their information quota. They can also click a checkbox that denies Flash Cookies from saving anything to their computers. If this is the case, your Flash should present the standard fields for re-entering this data and storing it as variables inside the Flash, this way you can be sure your movie will run if it requires personalized data. In fact, I’d recommend not storing information to cookies that would disable your movie if not present even if you provide the aforementioned standard fields.

Here’s how it works. First, create a SharedObject on the first frame of your Flash:

var local_data:SharedObject = SharedObject.getLocal(”user_data”);

Then store whatever you want to it:

local_data.data.user_name = “Don”;

Then, optionally, you can force the Flash to store the data immediately, rather than waiting for the movie to be closed:

local_data.flush();

And, that’s it! Referencing the stored data is just as easy:

trace(local_data.data.user_name); //Outputs: Don

Feedback and questions always welcome.

Download Flash Cookie Example (RAR)
Includes:
Flash FLA, Flash SWF, SWFObject
Looking for more Flash stuff?
Why not visit my company site:
www.era404.com

  • Code Subpages

    • Activating an ActiveX Control’s Interface through Javascript
    • Blur Effect
    • Cursor Illusion
    • Flash Meta-Preloader
    • Flash Plug-in Detection and Upgrading
    • Flash File Uploader
    • Flash Cookies
  • Categories

    • Code Examples (12)
    • Illustrations (6)
    • Journal Entries (32)
    • News (124)
    • Photography (24)
    • Poetry (11)
    • Prose (5)
    • Sketches (8)
  • Archives

    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
    • September 2007
    • August 2007
    • July 2007
    • June 2007
    • May 2007
    • April 2007
    • March 2007
    • February 2007
    • January 2007
    • December 2006
    • November 2006
    • October 2006
    • September 2006
    • July 2006
    • June 2006
    • April 2006
    • March 2006
    • January 2006
    • June 2005
    • April 2005
    • February 2005
    • September 2004
    • February 1999
    • January 1999
    • December 1997
  • Links

    • era//404 Creative Group, Inc.
    • SwissMiss
    • Fischler.org
    • Picture Calendar
    • My Flickr Page
    • My MySpace Link
    • My Friendster Page
    • My Faceparty Link
    • Citarella.net
    • Venice
    • Spain
    • France, Switzerland, Germany
    • England
    • Ireland
    • Fuse Number 8
    • My Facebook Page
    • My Maddened Mind
    • Prague
    • Vienna
  • Recent Comments:

    • Don: Hi Narsil, Sorry I didn’t see this sooner, I would’ve been happy to send you the modified FLA. Glad...
    • Narsil: Hey Don, I went ahead and downloaded the demo of Flash CS3 and made the necessary edit. Thanks!! I love this...
    • Narsil: Don, Regarding the “All Files” capable upload.. The way I am going to be implementing the Flash...
    • Don: Hi Narsil, Glad you got it fixed. A 403 error (forbidden) means you’re attempting to perform a task that...
    • Narsil: Hey Don! I got my previously problem fixed. I really am not sure why it wasn’t working, but it is now....

Copyright © 2008 [d]online. All Rights Reserved.
Entries (RSS), Comments (RSS). Valid XHTML, CSS. Proudly powered by WordPress