SharedObjectManager v1.1 Updates

Reader Stéphane e-mailed me last week with a problem he was having using the SharedObject in Flash. Basically, Stéphane wanted to save some data in one SWF file to a SharedObject and then retrieve that data in another SWF file. I had done this before many times but quickly realized that I had only done this with the same SWF file later loading that data back in. I did a little thinking about it and I quickly realized the error of my ways.

Basically, and according to the Adobe docs for the SharedObject class, you have to add a localPath parameter to your SharedObject call if you want to retrieve the SharedObject in another SWF. I went ahead and made the call to the SharedObject look like the following:

Actionscript:
  1. var so:SharedObject = SharedObject.getLocal("userData", "/");
  2. so.data.userName = "Matt";
  3. so.flush();

Then, when I went ahead and tried to call that in the second SWF file, all I had to do was this:

Actionscript:
  1. var so:SharedObject = SharedObject.getLocal("userData", "/");
  2. trace("Username: " + so.data.userName);

This only worked after I put in the extra localPath parameter (in this case I simply used "/") in the SharedObject call. I quickly realized that I needed to update my SharedObjectManager classes (for both AS2/AS3) to allow in the passing of the localPath parameter. I went ahead and threw in the secure parameter as well in case anyone needs it. I've updated the AS2 and AS3 versions to version 1.1 and you can grab the updated files at the respective links. I've also updated the documentation to reflect the change that was made.

If you found this post useful, please consider leaving a comment, subscribing to the feed, or making a small donation.

2 Comments

Good work.

Yeah, thanks for the help, the SharedObject Manager is very useful.

Leave a comment

(required)

(required)