PDA

View Full Version : Shared objects in AS3


heppa
10-15-2009, 07:13 AM
Hi guys,

I recently started on AS3 and I have a strange issue with Shared Objects that I can't figure out.

Take this simple code:


import flash.net.SharedObject;
var so:SharedObject = SharedObject.getLocal("userDataAS3");
so.data.username= "user1377";
so.flush();



It creates the shared object like this (viewed with SOL editor):

http://www.cpguru.com/demonstrations/cookieAS3.jpg

The format looks all screwed up. It doesnt matter if I define the value as String, Number or anything else. It always appears like this in the Shared Object. When it's like this I can't access the value.

If I create the exact same thing in AS2:


var so:SharedObject = SharedObject.getLocal("userDataAS2");
so.data.username= "user1377";
so.flush();


http://www.cpguru.com/demonstrations/cookieAS2.jpg

Here the shared object looks nice and tidy and I can access the value without any problems.

Can anyone explain to me what is happening and why the AS3 version is "garbled"?

Thanks in advance.

/Michael

RogerClark
10-15-2009, 07:31 AM
heppa,

Have you tried reading the shared object back into AS3

e.g. just doing

import flash.net.SharedObject;
var so:SharedObject = SharedObject.getLocal("userDataAS3");
//so.data.username= "user1377";
//so.flush();

trace(so.data.username);

After first setting the data.

It reads back OK.

I suspect that Adobe have changed the format in which they store the stored object between AS2 and AS3

If you look at the date on the SOL Editor from Sourceforge its dated at
Mon Feb 21 2005 11:47 which is firmly in AS2 territory.

You generally can't really rely on third party apps to interact with things like the shared objects or the local connection, as Adobe can and do change the internal representation of the data.

The only reliable way is always to use Flash or AIR

heppa
10-15-2009, 08:13 AM
Christ.. I was so focused on that garbled stuff that I didn't even think of tracing the value.

I had a function in my code that would read back the value and use it in the code, but it didnt work and I assumed it was because of the "garbled" data.

It turns out that the error was in a different line of code.

Thanks a million Robert!

Best regards,
Michael

henke37
10-15-2009, 12:50 PM
Adobe made a new version of amf, I am surpriced that the program didn't crash for you when wrongly interpreting the data.