View Full Version : Setting Flash Cookies "local shared objects"
zuser
08-13-2007, 08:11 PM
Hello,
I came across this interesting concept of flash cookies lately :confused:
Can anyone help me with an example of how to set this flash cookie using javascript/html ? If you would point me to an existing tutorial, that would be great too.
I searched around in the web, i came acroll lots of instances of setting the normal browser cookie using flash, but not the other way round, ie setting the flash cookie
(local shared objects) using javascript.
thanks
CyanBlue
08-13-2007, 08:44 PM
Howdy and Welcome... :)
You CANNOT set the Local Shared Object with HTML/JavaScript... You do need the SWF to do the job...
zuser
08-13-2007, 11:17 PM
Hello Cyanblue, thanks for your reply :)
My objective is to set a flash cookie and use it to pass info to server. and unfortunately i dont have any swfs anywhere.
Can i do it the following way.
1. Create a non-visible swf (ie will not be displayed in the browser) whose only job
is to set the cookie and return the cookie value. Embed this swf in the html.
2. From Javascript call some method from the above swf to either set/get the
cookie value and pass it along ?
I came across some javascript modules that i guess try to do that , like
http://blog.deconcept.com/swfobject/
Can you tell me whether my approach is feasible :confused: and if yes, a skeleton swf please :p as i could not figure out how to write a simple hello world swf :o
CyanBlue
08-14-2007, 01:03 PM
Yes, your approach should do the job for you... You can create 1x1 SWF with no problem...
No, that's not a good excuse and I won't create one for you... Maybe I will if it is something really unique, but it is not... There are plenty of Shared Object related threads in the forum, or on the Internet... Read the threads, download & dissect the sample and learn from it to make one for your project...
zuser
08-14-2007, 01:30 PM
:p Thanks Cyanblue for your suggestion. as per you, i see that this is a simple task, i shall try. :)
CyanBlue
08-14-2007, 01:36 PM
I can tell you that this is not really hard one especially when you know how to use JavaScript... ;)
zuser
08-15-2007, 07:27 PM
I can tell you that this is not really hard one especially when you know how to use JavaScript... ;)
Hello CyanBlue,
After some slogging to understand the flash/actionscript concept, :eek: i came up with this, i can successfully set the flash cookie, but am unable to figure out, how to send it back to the server, along with the POST of the html containing this flash, instead of directly from the flash.
Now i have a swf which is loaded in the page, if one input parameter (fldata) is passed via flashvars, i set the cookie, if that is not passed, i get the local shared object and pass it to the server. Unfortunately the sendAndLoad seems to POST the data by itself, and does not wait for the form containing this swf to be submitted :confused: Below is the actionscript, can you give me some pointers on how i can have a OUT param from flash (just like FlashVars is a kind of IN param), so that i can collect whatever is given out by flash in javascript and then pass it to the server back with the htmls post
function done()
{
if (_root.gotoUrl != undefined)
{
getURL(_root.gotoUrl, "_self");
}
}
function incomingHandler(success)
{
if (success)
{
if (incoming.fldata != undefined)
{
var loc = SharedObject.getLocal("flcookie");
loc.data.fldata = incoming.fldata;
loc.flush();
}
}
done();
}
var flfso = SharedObject.getLocal("flcookie");
if (_root.fldata != undefined)
{
flfso.data.fldata = _root.fldata;
flfso.flush();
}
else
{
var fldata = flfso.data.fldata;
if (fldata == undefined)
{
fldata = "";
}
var incoming = new LoadVars();
incoming.onLoad = incomingHandler;
var outgoing = new LoadVars();
outgoing.fldata = fldata;
outgoing.sendAndLoad(_root.sendUrl, incoming, "POST");
}
CyanBlue
08-15-2007, 09:54 PM
Maybe I am not fully understanding what's going on, but it looks like the code should be working... Are you saying that basically the sendAndLoad() line is not posting the data back to the sendUrl???
zuser
08-16-2007, 01:58 PM
Maybe I am not fully understanding what's going on, but it looks like the code should be working... Are you saying that basically the sendAndLoad() line is not posting the data back to the sendUrl???
Hello Cyanblue, sendAndLoad is posting as soon as the swf is loaded by the surrounding html page.
While what i needed was that it should post when the submit button of the surrounding html is pressed. ie we have a <form> and within that this swf is there, and in the <form> there are few more <inputs> which the user will input, and this flash data should be sent along with them, when the user clicks on the submit of the html.
If that is not possible, is there anyway i can access the parameter from flash and store it in a javascript variable, and when the html submits its POST at that time, pass the flash cookie data too..
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.