views:

514

answers:

3

I am trying to share data between an as3 swf and a as2 swf that it loaded. The problem is, I can't seem to get my as2 swf to read the localshared object written by the as3 swf. It simply returns undefined when I try to get a reference to the shared object

// AS3

_SharedObj.objectEncoding = ObjectEncoding.AMF0;
_SharedObj.data.blah = 'str';
_SharedObj.flush(500);

// ... some code to handle the flush status. I verified that the values were flushed.


// AS2

var so = SharedObject.getLocal('somestr', '/');
trace(so);  // undefined!

I am at a loss here. I can read the AS2 sharedobject from AS3, but I can't do it the other way. I have verified that both are referencing the same path '/' (specifically localhost, I even checked the physical file in the filesystem, - its in the #localhost directory of the #SharedObjects directory on my mac) The objectEncoding is set to use the AS2 AMF format.

The docs specifically say to set this encoding to allow as2 to access the same shared object, so I assume it means this is possible.

Anyone have any ideas?

A: 

Your problem is swf id generated for Flash Player and use by it for SharedObject use. You don't see this in code but when you search for SharedObject file then you see it. That is safety feature. I don't know any work around for that.

Konrad
A: 

I ran into a similar problem -- we eventually went the heinous route of reading/writing the LSO with an AS2 SWF, and having it talk to the AS3 SWF via JavaScript/ExternalConnection. It was gross, but it worked reliably.

JMHNilbog
A: 

Can't figure what is not working for you, when using FlashDevelop, the following code works perfect for me:

//AS3
var so : SharedObject = SharedObject.getLocal('somestr', '/');
so.objectEncoding = ObjectEncoding.AMF0;
so.data.blah = 'str';
so.flush();

//AS2
var so = SharedObject.getLocal('somestr', '/'); 
trace(so.data.blah);  // str
Dudi