Section 8.1. Objects and Shared Objects

8.1. Objects and Shared Objects

ActionScript objects are implemented as associative arrays. Each object property associates a value with a property name. The property name is a string that is used to store and retrieve a value in a slot, or location, within the object. Objects are similar to arraysthey have slots that hold values. Arrays are designed to provide access to the value in each slot via an index number, while objects provide access to values via a string property name . Example 8-1 reviews how to add properties to a generic ActionScript object.

Example 8-1. Creating and adding properties to an ActionScript object
 // Create a simple object named   user   . user = new Object( ); // Use dot notation to add a   userName   property. user.userName = "blesser"; // Use the [] operator to add a   password   property. user["password"] = "bigSecret"; // Add a function as a property of this generic object. user.showProperties = function ( ) {   for (var prop in this) {     trace(prop + ": " + this[prop]);   } }; // Call the function. user.showProperties( ); // Output to the Output panel for this script: showProperties: [type Function] password: bigSecret userName: blesser 

In ActionScript, objects are the foundation on which custom classes are built. However the SharedObject class cannot be extended the same way as other classes. Shared objects always store data in a simple associative array. Shared objects can contain instances of other classes in their slots (i.e., properties); however, there are some restrictions on the type of data that can be stored in a shared object's slots. With one exception, a shared object slot can contain any native ActionScript type such as a Number , String , Date , Boolean , Object , or Array . However, an LSO cannot be used to store and retrieve a function in a later session, and RSOs cannot make a function available to remote movies by assigning one to a slot. However, with an added step of registering a class in a movie, a shared object slot can contain custom classes, provided they are also defined in each Flash movie or in the server-side application where they are accessed.



Programming Flash Communication Server
Programming Flash Communication Server
ISBN: 0596005040
EAN: 2147483647
Year: 2003
Pages: 203

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