Recipe 17.4. Reading Data from a Shared Object


Problem

You want to read values that have been previously written to a LSO.

Solution

Read the values from the properties stored in the shared object's data property.

Discussion

There is nothing difficult about reading the values from a client-side shared object. All persistent values are stored in the shared object's data property, so you simply read the values from the data property, as follows:

// Read the value of exampleProperty from the shared object,  // example, and display it in the Output window. trace( example.data.exampleProperty );

By using a combination of reading and writing data, you can determine if this is the first time a user is viewing a .swf file.

// Create a shared object and store some data in it var example:SharedObject = SharedObject.getLocal( "example" ); if ( example.data.previouslyViewed ) {   // The user has already viewed the .swf file before, perhaps   // we skip an introductory help screen here.     } else {   // This is the first time the user is viewing the .swf file   // because previouslyViewed has not yet been set to true.   // Set previouslyViewed to true so that the next time this   // code is run we know the user has been here before.   example.data.previouslyViewed = true;   example.flush(  ); }




ActionScript 3. 0 Cookbook
ActionScript 3.0 Cookbook: Solutions for Flash Platform and Flex Application Developers
ISBN: 0596526954
EAN: 2147483647
Year: 2007
Pages: 351

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