R – Writing Local SharedObject in AS3 swf and reading it in loaded AS2 swf

actionscript-2actionscript-3flashshared-objects

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?

Best Answer

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
Related Topic