Extending the Framework

As it is presented, the framework stores the user’s settings in a local shared object on the user’s computer. Ideally, however, the application should save the data in a way that the user’s preferences can be retrieved from any computer. This can be accomplished in a variety of ways. The data could be stored to a database, a text file, an XML file, or using a FlashCom Server remote shared object. The following example stores the data to an XML document on the server. Without relying on a FlashCom server remote shared object or other proprietary system, the solution uses an ActionScript class, a simple server-side script for file I/O operations, and an XML document. Refer to Chapter 19 for more information on saving and retrieving XML.

Making a Server-Side Shared Object

Without much modification to the framework movie, you can have it use a server-side faux shared object instead of a local shared object (or instead of a true FlashCom server remote shared object). First, let’s understand how the process works. Using an ActionScript class, FauxSharedObject, you can mimic the operations of a local shared object. You can perform the saving and retrieval operations by serializing and deserializing the data with XML, and then use a server-side script (ColdFusion in this case) to perform the file operations.

Save the FauxSharedObject class definition, shown in the following example, in an ActionScript file named FauxSharedObject.as and place it in Flash’s Include ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.