Writing local SharedObject to swf AS3 and reading it to loaded AS2 swf

I am trying to exchange data between as3 swf and as2 swf that it was downloading. The problem is I can't get my as2 swf to read the localshared object written by as3 swf. It just returns undefined when I try to get a reference to a 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'm at a loss here. I can read AS2 sharedobject from AS3, but I cannot do it any other way. I have checked that both refer to the same '/' path (specifically localhost, I even checked the physical file on the filesystem - it's in the #localhost directory of the #SharedObjects directory on my mac). ObjectEncoding is set to use AS2 AMF.

It is stated in the docs to set this encoding to allow as2 to access the same shared object, so I guess this means it is possible.

Does anyone have any idea?

+2


source to share


4 answers


Can't figure out what doesn't work for you, when using FlashDevelop, the following code works great 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

      

+2


source


Your problem is the SWF ID generated for Flash Player and used by it to use the SharedObject. You don't see it in the code, but when you look for the SharedObject file, you see it. This is a safety feature. I don't know how it works.



0


source


I ran into a similar problem - we ended up taking the disgusting LSO read / write route with AS2 SWF and talked to ASF SWF via JavaScript / ExternalConnection. It was rough, but it worked reliably.

0


source


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 by Shared Object.

so.objectEncoding = ObjectEncoding.AMF0

      

Thanks Dudi!

0


source







All Articles