Groups | Blog | Home
all groups > flash (macromedia) > july 2006 >

flash (macromedia) : Cookies from flash to asp


muzila
7/2/2006 6:00:33 PM
I have a flash movie that creates a cookie called "cart_data". I want to
request the cookie in an asp page with the following code:
tempArray = Request.Cookies("cart_data")

the problem is, it doesn't work. I believe that the asp cannot find the cookie
that was made by flash

Is there a solution to this?
secret_warrior
7/2/2006 6:14:25 PM
Flash doesn't create cookies, like browsers do. It's similar but different.
Flash Player does NOT store the "shared object"
or "cookie" in the temp folder but in the Flash Player #Shared Objects
folder within the Flash Player folder of Document and Setting folder within
the Current Users Folder under Application Data -> Macromedia -> Flash Player
-> #SharedObjects -> SXCBJSF -> local

And then the file in many cases is not readable by human eyes and is NOT in a
browser standard cookie format. Some are human readable but compare one to a
cookie placed from a browser and you will see they are NOT the same.

At least that is what I have discovered. If I am wrong, which is possible,
someone let me know so I can update my knowledge on this.

Thanks
muzila
7/2/2006 9:42:48 PM
Well, if i cannot use cookies, what should i do. I previosly tried to use a
query string:

getURL("http://www.custombrackets.com/scripts/cart.asp?cartArray="+_global.cartA
rray, "_self"); in flash
and
tempArray = Request.QueryString("cartArray") in asp.

but this only worked in firefox, and not in internet explorer.
Wolf van Ween
7/2/2006 9:44:34 PM
So called Flash cookies and browser cookies (the ones set and retrieved by ASP)
have nothing in common. Either use a shared object between two swfs on two
separate webpages or send information from Flash into the containing page and
have some javascript code there handling the cookie read/write.
Wolf van Ween
7/2/2006 9:48:23 PM
What is cartArray? An Array? If so, how is it serialized? (changed into a
string) Did you urlencode it?
Generally the code you gave is ok, there is no reason why it shouldn't work in
IE for a single piece of data, e.g. a number.
muzila
7/3/2006 12:15:38 AM
here is the complete code i am using in flash and asp (i am sending a number
array from flash to asp)
In
Flash:getURL("http://www.custombrackets.com/scripts/cart.asp?cartArray="+_global
..cartArray, "_self");
(where cartArray is an array of numbers such as: cartArray = (12,33,128,222)

In ASP:
tempArray = Request.QueryString("cartArray")
tempArray = Split(tempArray, ",")
for j = 0 to uBound(tempArray)
if isNumeric(tempArray(j)) then
addItem()
end if
next
end if
Wolf van Ween
7/3/2006 11:08:01 AM
You rely far too much on implicit conversions.

In Flash create a
var cartString:String = _global.cartArray.join();
then
instead of _global.cartArray use escape(cartString) in the getURL call.

I think the Request.QueryString function of ASP does automatic url-decoding,
but I'm not sure. Better look that up.

Cheers
Wolf
muzila
7/3/2006 9:22:20 PM
i got the excape function working, i had to use tempArray = escape("cartString") in asp.

Wolf van Ween
7/4/2006 12:00:00 AM
I think you need to do a bit of "tracing" here and tell us the results. I would
first make copy of the asp script and change it so that it only shows the query
string.
This should be urlencoded, so the escape has to work.
Your query string should look like this:
http://www.custombrackets.com/scripts/cart.asp?cartArray="12%2C33%2C128%2C222
using the example of (12,33,128,222) you gave above.
If it does look like this, the problem is in ASP or more generally on the
server side
if it doesn't look like this, it's in Flash

Then you unescape this in ASP, split it into a tempArray, and Response.Write
this array. (My suspicion is you get non-numeric values and this causes a
problem with the next loop)

Then you do your loop and Response.Write in your addItem() function

Of course, if the problem is in Flash, we need to look somewhere else. But I
don't think that's the case.

Good luck
Wolf
Wolf van Ween
7/4/2006 12:00:00 AM
PS: I just tested this by hand: I entered above query string (both
urlencoded=escaped and with commas) by hand into IE, and your asp script
returned "Your shopping cart is empty". Did you change anything in between?
Before you play with Flash, make sure it works from the browser's adress bar
first.
AddThis Social Bookmark Button