Flex, ActionScript and Related Stuffs

Enjoy!!!!

Shared Objects in Flex, ActionScript 3.0 – Basics

Posted by flexrays on October 4, 2007

Shared Objects are used to store data outside of the Flash Player

There are two types of Shared Objects
1. Local shared objects – LSOs
2. Remote shared objects – RSOs

LSO is similar to browser cookies

But what are cookies..Cookies have got the ability to remember the user information so that the user doesnt have to manually login during each visit..

LSO Vs Cookies

LSOs are can store more data than cookies
LSOs never expire
LSOs arent transmitted between the client and the server
LSOs can store native ActionScript datatypes.

Uh!! Cool isnt it??

LSOs are to Flash (Call it Flash cookies)
Cookies are to web browsers

LSO files are saved to the client computer in a binary file ending with a .sol extension
Flash movies with in the same domain can read from or write to the .sol files by means of ActionScript’s flash.net.SharedObjects

The static getLocal() method is the mechanism by which LSOs are both created and opened for reading

var example : SharedObject = SharedObject.getLocal(“example”);

Remote Sharing Objects

RSOs are created using the static getRemote function. This returns a reference to an object that can be shared across multiple clients by means of a server, such as Flash Media Server. If the shared object does not already exist, this method creates one.

The following code shows how you assign the returned shared object reference to a variable:

var myRemote_so:SharedObject = SharedObject.getRemote(name, remotePath, persistence);

To create a shared object that is available only to the current client, use SharedObject.getLocal().

After calling this method, use SharedObject.connect() to connect the object to the application server, as shown in the following code:

var myNC:NetConnection = new NetConnection();
myNC.connect(“rtmp://[yourDomain].com/applicationName”);
var myRemoteSO:SharedObject = SharedObject.getRemote(“mo”, myNC.uri, false);
myRemoteSO.connect(myNC);

To confirm that the local and remote copies of the shared object are synchronized, use the sync event.

All clients that want to share this object must pass the same values for the name and remotePath parameters.

One Response to “Shared Objects in Flex, ActionScript 3.0 – Basics”

  1. Arindam Mojumder said

    Super explanation. It is really clear my idea. Can you post more example regarding share objects.
    What kind of data I can store in a share object? I mean how can I store and fetch data through share object? Need more clarification.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>