MrArbi
MrArbi

Reputation: 25

Cookies with flash player

I would like to know how can I do to create a flash cookie to track visitors.

For more info I have make the same thing using html and appnexus to get the ID of the visitors.

Upvotes: 0

Views: 134

Answers (2)

Kevin
Kevin

Reputation: 2697

As "Creative Magic" stated, you can use SharedObjects to persist data in Flash similar to how you would use cookies to persist data in Javascript.

Given that you made references to "html" and "ID of the visitors", I'm going to assume that you wish to accomplish this in the context of a browser window.

If I'm correct, you should know that you cannot directly utilize SharedObjects with Javascript. You should also know that you can so indirectly through Actionscript code (an example of which "Creative Magic" included in his/her answer).

First, you will need to encapsulate your ActionScript code in a method, and then register that method as part of the ExternalInterface of its parent application:

function handleObjects(/*param1, param2, ... */):void {/*code*/}
ExternalInterface.addCallback("handleObjects");

Second, you will need to compile your Actionscript application (your code), and create an element in your HTML that references the resultant .swf file.

Then, assuming the aforementioned HTML element is represented as a DOMElement named flashDOMElement, you can call your method with the DOMElement:

flashDOMElement.handleSharedObjects(/*arg1, arg2, ... */);

Check out BakedGoods if you don't want to go through the trouble of doing all of this; its a Javascript library that establishes a uniform interface that can be used to conduct common storage operations in all native, and some non-native storage facilities, including Flash Locally Shared Objects.

With it, creating an LSO can be accomplished with code as simple as:

bakedGoods.set({
    data: [{key: "key", value: "value"}],
    storageTypes: ["flash"],
    complete: function(byStorageTypeRemovedItemKeysObj, byStorageTypeErrorObj){/*code*/}
});

Retrieving and removing data is just as easy. Trust me on all of this, I would know; i'm its maintainer :)

Upvotes: 0

Creative Magic
Creative Magic

Reputation: 3151

There's SharedObject that can be described as Flash cookies.

Here's a small example how to remember the last time the user logged in:

var sharedObject:SharedObject = SharedObject.getLocal("testObj");

if (sharedObject.data.id == null)
{
    sharedObject.data.id = 20;
    sharedObject.flush();
}

trace(sharedObject.data.id); // 20

The id object will be saved and can be accessed/modified later.

For more info on SharedObject follow the link: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html

Upvotes: 1

Related Questions