PDA

View Full Version : Sharedobjects... but how shared ?



jess
July 5th, 2004, 01:21 PM
:beer: Salut salut !

I create and populate a sharedobject in A.swf, like this :

var myCookie = SharedObject.getLocal("user_profile");
if (myCookie.data.firstname == undefined) {
myCookie.data.firstname = "cowboy";
myCookie.flush();
}
else {
myCookie.data.firstname = "cowgirl";
myCookie.flush();
}

I want to retrieve this stored data, in B.swf, which is located beside A.swf, like this :

var myCookie = SharedObject.getLocal("user_profile");
myTextfield.text = myCookie.data.firstname;


The problem is that I always get "undefined" in place of "cowboy" or "cowgirl".

:ogre:

What I'm doing wrong ?

thxx a lot :)

jess
July 6th, 2004, 06:40 AM
Really no idea guys ?... :*(

Why can't I get my sharedobject.data.firstname from that other swf ?

I can't get it.

Look simple but really can't get rid of that problem...

jess
July 6th, 2004, 07:31 AM
Well... me again :hugegrin:

In other terms, DOES ANYBODY MANAGE TO READ SHAREDOBJECTS THAT HAV BEEN CREATED IN A SWF, FROM WITHIN ANOTHER SWF (but placed beside the first one) ?

Jerryscript
July 7th, 2004, 02:55 AM
In order to share the SharedObject between different swf movies, you need to set the path in your getLocal statement after the name of the SharedObject. In this case, just set the path to the current folder:

A.swf:
var myCookie = SharedObject.getLocal("user_profile","/");
if (myCookie.data.firstname == undefined) {
myCookie.data.firstname = "cowboy";
myCookie.flush();
}
else {
myCookie.data.firstname = "cowgirl";
myCookie.flush();
}
B.swf:
var myCookie = SharedObject.getLocal("user_profile","/");
myTextfield.text = myCookie.data.firstname;

jess
July 7th, 2004, 05:05 AM
Simple as that !

it works now, thxx for your answer Jerryscript :thumb: