Are AS2 and AS3 sharedobjects compatible?
Copy link to clipboard
Copied
I have a legacy AS2 file that stores a nested array in a sharedobject. I have a new file in AS3 that I would like to read and write to that sharedobject. Both swfs will be in use and so should be able to read and write to the same variables in the same sharedobject. Is that possible?
Here is the code I set up as a test, it is identical in AS2 and AS3...
var so:SharedObject = SharedObject.getLocal("testso", "/");
if(!so.data.arr) so.data.arr = new Array();
trace("retrieved: " + so.data.arr);
so.data.arr = "as2"; // I change this to "as3" when I compile using actionscript 3
so.flush();
I have failed to read the variable in both AS2 and AS3 when it is set by the other, and getting "out of bounds" errors in AS3.
Thanks,
Josh
Copy link to clipboard
Copied
From the help files
objectEncoding | property |
objectEncoding:uint
[read-write] Language version: | ActionScript 3.0 |
Player version: | Flash Player 9 |
The object encoding (AMF version) for this shared object. When a local shared object is written to disk, the objectEncoding
property indicates which Action Message Format version should be used: the ActionScript 3.0 format (AMF3) or the ActionScript 1.0 or 2.0 format (AMF0).
Object encoding is handled differently depending if the shared object is local or remote.
- Local shared objects. You can get or set the value of the
objectEncoding
property for local shared objects. The value ofobjectEncoding
affects what formatting is used for writing this local shared object. If this local shared object must be readable by ActionScript 2.0 or 1.0 SWF files, setobjectEncoding
toObjectEncoding.AMF0
. Even if object encoding is set to write AMF3, Flash Player can still read AMF0 local shared objects. That is, if you use the default value of this property,ObjectEncoding.AMF3
, your SWF file can still read shared objects created by ActionScript 2.0 or 1.0 SWF files.
Copy link to clipboard
Copied
so, why'd you have a problem setting the so using as2 and retrieving it with as3?

