Introduction

You already know how to work with data that is stored in memory as long as a Flash movie is open. In fact, almost all data you work with in ActionScript is of this type. But what if you want to be able to store data between Flash movie sessions? Or what if you want to be able to share data between Flash movies running on the same client, or even on different clients? To accomplish these feats, we'll need to look at how we can store and transmit data outside of the Flash Player.

This chapter addresses both client-side and server-side data. First, we'll examine client-side data. Prior to Flash 6, the only way to store persistent data on the client was with complex techniques that invoked external JavaScript functions to read and write cookies. However, Flash 6 introduced local shared objects to ActionScript, making it possible to store and retrieve persistent data on the client without the use of these other, complicated techniques.

We'll also take a closer look at server-side data. Prior to Flash 6, server-side data manipulation was limited to invoking server-side scripts (using loadVariables( ) or an XML object) to read and write data to text files and/or databases on the server. The problem was, of course, that this functionality required that you had the necessary scripts on the server. While this kind of functionality still has its place (although the LoadVars class supercedes the older loadVariables( ) method), this chapter examines how remote shared objects, used in conjunction with FlashCom, allow us to work with server-side data in a different way.

Shared objects come in several varieties. Local shared objects (LSOs) are similar to browser cookies in that they are stored on the client's machine. Local shared objects are useful for storing the same kinds of information for which cookies have traditionally been used, such as the capability for a web site to remember a user so that the user does not have to manually log in during each visit. But LSOs are more powerful than cookies because they can store more data than cookies and store native ActionScript datatypes. Local shared objects are available to any Flash 6 movie, and they do not require any additional software on the client or on the server.

In contrast with local shared objects, remote shared objects (RSOs) are available only for movies that are clients of a Flash Communication Server MX (FlashCom) application (see Chapter 14). Remote shared objects allow you to store persistent data that is accessible by all clients of that application. Remote shared objects can also be used for nonpersistent data sharing between clients (see Recipe 16.5).

Local shared objects exist on the client only. On the other hand, remote shared objects must be opened on both the client and the server. Throughout this chapter, we refer to shared objects that are opened on the client (whether local or remote shared objects) as client-side shared objects, and we refer to shared objects opened on the server (using code within an .asc file) as server-side shared objects. This is an important distinction because the ActionScript that you use in each case is different.



ActionScript Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2005
Pages: 425

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net