2
votes

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?

4
Can you post the link to the docs about this? Btw, if you can't get this to work, consider using LocalConnection for communication between as3 and (loaded or other) as2 swfs.Amarghosh

4 Answers

2
votes

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
0
votes

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.

0
votes

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.

0
votes

I had the same problem and I think Dudi's answer above is the way to go - I added the following line to my code after calling SharedObject.getLocal() and my AS2 swf was able to load my AS3 written Shared Object.

so.objectEncoding = ObjectEncoding.AMF0

Thanks Dudi!