Tiago Tiago - 1 year ago 78
Javascript Question

Javascript bridge to Flash to store SO "cookies" within flash

After reading this on the question How do I uniquely identify computers visiting my web site?

A possibility is using flash cookies:

Ubiquitous availability (95 percent of visitors will probably have


You can store more data per cookie (up to 100 KB)

Shared across browsers, so more likely to uniquely identify a machine

Clearing the browser cookies does not remove the flash cookies.

You'll need to build a small (hidden)
flash movie to read and write them.

I tried to find if someone has already done something like this, so I wouldn´t have to reinvent the wheel. So far, no luck(maybe I don´t know the right term to search), except for the code in the flash side

The use I have for this is to prevent a user to answer a quiz multiple times, but future uses maybe banning trolls.

Does anyone knows a open source library that does this and allows me to access via javascript?

Caveats: I don't know flash and I don't own a license.

Edit: You can do that using evercookie. It's kind of evil, but works.

Answer Source

To build on what rmeador said, and to help get you started, you are going to need to know how to use two classes in the FLEX3 API, SharedObject and ExternalInterface.

SharedObject will allow you to store and retrive data from a client computer and ExternalInterface will allow your actionscript to communicate with your javascript.

Using shared object is simple.

To put data onto a users machine just create a SharedObject and add properities to the sharedObject's data properity.

  private var sharedObject : SharedObject = SharedObject.getLocal("myCookie");
  sharedObject.data.DATA_FOR_THE_COOKIE = DATA;

Retriving data from the SharedObject is just as simple. Make sure the size of the SharedObject is greater than 0 (Make sure the SharedObject exists) and the just look up the properity names through the SharedObject's data properity.

if(sharedObject.size > 0)
       // access data from cookie with -> sharedObject.data.DATA_FROM_THE_COOKIE;

To pass the data stored in the SharedObject to your javascript you are going to need to use ExternalInterface.

Lets say you have a javascript function to retrieve the variables

function retrieveVars( vars ){
   // Do something with vars.

To call this function from actionscript you will use

ExternalInterface.call("retrieveVars", DATA_ITEM_1, DATA_ITEM_2, ...);

Its that simple.

Please note that this technique will not work if the client's flash player has its storage settings set at 0, or if the client's browser does not have ActiveX or NPRuntime.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download