Processing
 

Is it possible to set the same cookies in Flash as they are used in browser

10/07/2012 08:30#1

avasin

Member

Joined at: 8 months ago

Post: 1

Thank: 0

Thanked: 0

I use js plugins like uploadify, that uses swf (flash) as uploader (to provide ajax upload). I can perform upload operation only for logged-in people. But as my website authentication happens not via flash, flash doesn't have cookies as browser has after authentication.

So, in browser i am an administrator, in flash i am guest. Is there a way to setup the same cookie for flash as i have in browser to identify myself without additional hashes or other extra functionality?

Will be happy to any help/advices/links to docs/manuals. Thank you in advance!

10/07/2012 09:05Top#2

strah

Member

Joined at: 12 months ago

Post: 74

Thank: 0

Thanked: 0

You can use Javascript to set and read cookie(s) and then use ExternalInterface to pass values to/from Flash.

Or you can use SharedObject to set/read your 'cookies' and then pass the values to the website (ExternalInterface).

05/07/2016 00:09Top#3

Kevin

Member

Joined at: 12 months ago

Post: 313

Thank: 0

Thanked: 0

As strah stated, through a combination of ExternalInterface and SharedObject, you can persist data in Flash similar to how you would use cookies to persist data in Javascript. How do you go about doing this, you ask?

First, you will need to write the ActionScript code which utilizes one or more SharedObjects to persist data:

//Obtain the SharedObject named "cookie", procuring a reference //to the member Object containing its persisted data var locusLSO:SharedObject = SharedObject.getLocal("cookie"); var lsoData:Object = locusLSO.data; /////  //Establish a pairing in locusLSO between some key and value lsoData["key"] = "value";  //Immediately serialize the data contained in locusLSO to its linked file var statusStr:String = locusLSO.flush(); 

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

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

Third, 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.storeData(/*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 :)

Similar articles

Open a folder in finder/explorer from a webpage?

5 years ago - Reply: 2 - Views: 80

How do I escape a reserved word in Actionscript?

5 years ago - Reply: 2 - Views: 199

Save PPS/PPT files as SWF using C#

5 years ago - Reply: 2 - Views: 171

Ways of making a graphic/visual novel in flash

6 years ago - Reply: 3 - Views: 114

Use PhoneGap + HTML5 and an Embedded Flash Movie

5 years ago - Reply: 2 - Views: 96

View word docs and PDF in browser?

5 years ago - Reply: 2 - Views: 52

ActionScript 3 Read JPEG quality

7 years ago - Reply: 2 - Views: 59

Export/Test Movie Issues

5 years ago - Reply: 3 - Views: 39

Flash always on top in Android browser workaround?

5 years ago - Reply: 2 - Views: 149

Sending Json Form from Flash AS3

5 years ago - Reply: 2 - Views: 29

parsing a swf/fla (using php?)

6 years ago - Reply: 2 - Views: 44

Getting high FPS on Flash/AIR games for mobile?

5 years ago - Reply: 2 - Views: 59

vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re vé máy bay vé máy bay giá rẻ ve may bay ve may bay gia re