One of the problems I had when writing Flash Screensavr was sharing preferences between two separate and different SWF files – the Preferences panel and the Screensaver itself. Obviously a job for SharedObject.
However there is a trick to creating a SharedObject that behaves how you’d expect.
If you’re like me, you would think the correct code is;
But this results in a SharedObject which can only be accessed by the SWF that created it…not what I wanted. The not-very-obvious solution is to add a second parameter which is referred to simply as ‘localPath’ in the docs;
That’s it! You now have a useful SharedObject which you can access from any SWF on your machine. Having spent literally hours trying to track down the solution I decided to write a nice preferences class in a similar style to the one I use in Cocoa. Applications usually have unique preferences, so this is customised for each one.
I did think about having methods called ‘save’ and ‘load’ but was obviously feeling verbose that day. You could of course have this as a Singleton in Flash, but I didn’t need to.
The code for using the prefs is then as simple as this:
Constants.SHARED_OBJECT_ID is something like
I am an experienced Product Designer and Software Engineer with a passion for making and crafting digital products, tools and services that are useful, empowering or inspiring to others.