6/14/12

Shared Objects

Hi All,

I was working in my application and i gotta use the concept of cookies. Then i though of using Flex Shared objects. I just ran through the sites to find the difference between cookies and shared object, this is what the site says,

A browser cookie is a "small piece of text stored on a user's computer by a web browser. A cookie consists of one or more name-value pairs containing bits of information".

A web application uses cookies for session management, personalization and tracking. Most browsers restrict the size of a cookie to 4 kb.

In a Flex application, storing data on a user's computer for later use is accomplished using Local Shared Objects rather than cookies. A Local Shared Object can store up to 100 kb of data without asking permission of the user. Unlike cookies that are capable of storing only text values, Local Shared Objects can store many data types including Number, String, Boolean, XML, Date, Array & Object.
 


A simple Example for using shared object is as follows,

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
    <![CDATA[
        import mx.controls.Alert;
    var ob:SharedObject;
        private function setobj():void{
            ob= SharedObject.getLocal("setobj1");
            if(ob.size>0){
                Alert.show("shared object from --->"+ob.data.mydata);
                if(ob.data.mydata==undefined){
                    ob.data.mydata="test==="
                }
            }
            else{
                ob.data.mydata="test==="
            }
        }
       
    ]]>
</mx:Script>
    <mx:Button click="setobj()" label="click me" width="100" height="100" x="50" y="50" />
   
</mx:Application>

Following are the links where you can find the useful information and API information.

http://livedocs.adobe.com/flex/3/html/help.html?content=lsos_5.html

No comments:

Post a Comment

Popular Posts