sfmultimedia :: actionscript salons :: shared objects / local connections

Actionscript Salon #9: Shared Objects and LocalConnections

These two swfs walk into a bar. One swf says to the other...

Wait! Can swfs talk to each other? As of Flash MX, the answer is yes. LocalConnection allows swfs running on the same computer to share data, regardless of whether they're in the same browser window or even in the same application (eg, Explorer, Netscape, or the standalone player). This opens up some possibilities for swfs cooperating on tasks in multiple windows or in separate domains.

Swfs can also take advantage of SharedObjects, which I've best heard described as “cookies on steroids.” Allow your users to retain useful session data and customize their experience.

So one swf says to the other, “Will you have a drink?” The other swf replies, “Thanks, but I'm already pre-loaded.”

Relevance/availability: SharedObject and LocalConnection are available in Flash Player 6.

Presentation slides (swf)

Basic SharedObject. A simple demonstration of the SharedObject to save user name, password and a checkbox.

Download the .fla file (Zip 59k)

FlashWindows. A more complex SharedObject example. The user can open, move, and type text into windows (more like post-it notes, actually!). The window data is saved to a SharedObject "cookie" on the user's computer.

Download the .fla file (Zip 46k)

Basic LocalConnection . Here's the gist of the localConnection, using what is probably its most common application: two swfs on the same website which need to have a quick word.

Download the .zip file (Zip 25k)

Cross-Domain LocalConnection . Only slightly more complex (but subject to many more errors) is the cross-domain LocalConnection. In the example here, the receiver is located on this website and the sender is located at mtanenbaum.com. See it in action here.

Download the .zip file (Zip 26k)