4 Replies Latest reply on Mar 11, 2010 9:17 AM by cyber0897

    does the sharedObject get destroyed when the browser is closed?

    cyber0897 Level 1

      hey guys, so i just wanted to make sure that when my internet browser is closed it destroys or clears my sharedObject??

      right now i wasnt sure so im doing somehting like the following

       

      public var sharedObj:SharedObject;

       

      if(sharedObj != null){

           sharedObj.clear();

      }

      sharedObj = SharedObject.getLocal(...);

       

       

      i just wnated to make sure that this is the most effective way to destory the sharedObject just in case there is one left in the browser...

      is there another way to make sure i clear the sharedObjects??

        • 1. Re: does the sharedObject get destroyed when the browser is closed?
          David_F57 Level 5

          Hi,

           

          A shared object will only save data if it is flushed, which writes it to the local drive or the remote drive. Think of a shared object as a smarter more peristant cookie.

           

          If you create a shared object use it but don't flush it the behaviour then becomes the same as an array, just like any other memory object it is destroyed when the swf is closed, if you do flush the object(save it) then you need to programmatically clear the data if you don't want it to be available the next time the use accesses the swf.

           

          Local shared objects get stored in the use profiler on windows(not sure where on a mac), so you can have a look for the shared object if you want to see what is happening with it.

           

          this is the path to the SO for the sample app I gave you.

           

          D:\Profiles\David\AppData\Roaming\Macromedia\Flash Player\#SharedObjects\3K9EESA2\gumbo.flashhub.net\login.sol

           

           

          David

          • 2. Re: does the sharedObject get destroyed when the browser is closed?
            JohanVelthuis

            hello cyber0897,

             

            No sharedObjects are stored in a cookielike textfile on the clients harddrive, As far as I know there is not an option like with cookies to be destroyed after the browser closes.

             

            The reset you wrote should be in another order:

             

            var mySharedObject:SharedObject = SharedObject.getLocal....

            //the above will never give null, because it is created when it doesnt exist.

            //the if (object != null) is useless because of the above, in your post it will be always null, since it is not instantiated...

            mySharedObject.clear();

            mySharedObject.flush(); //not sure if this is neccesary

             

             

            You could reset the sharedObject when initializing your application, but if you just want to store variables and get them wherever you need them in your app you could use the singleton class below

             

             

             

            Usage:

             

            <s:TextInput id="text1" text="@{PrefObj.instance.myString} />

            <s:TextInput id="text2" text="@{PrefObj.instance.myString} />

            (the @ only works in flex 4)

             

            PrefObj.as

            package
            {
                import flash.events.EventDispatcher;
               
                [Bindable]
                public final dynamic class PrefObj extends EventDispatcher {
                    private static var _instance:PrefObj = new PrefObj();
                   
                    public function PrefObj(){
                        if (_instance != null){
                            throw new Error("PreferencesManager can only be accessed through PreferencesManager.instance");
                        }
                    }
                   
                    public static function get instance():PrefObj {
                        return _instance;
                    }
                   
                    //add your variables here:
                    public var myString:String = "";  
                }
            }

            1 person found this helpful
            • 3. Re: does the sharedObject get destroyed when the browser is closed?
              David_F57 Level 5

              Hi Johan,

               

              When you flush a local SO it writes to the local hard drive, this has always been the case, when an SO is created it writes an empty file to the drive which is stored in a folder that carries the swfs domain url in the path. If you don't write the data(flush) then the drive SO remains empty you can open  the SO file and test to see if it contains data next time you run the swf, if you run the same swf from a different location it will create/read the SO for that url.

               

              So the file may not be 'text' based but shared objects can be used in a cookie style way as per my provided login example. You can clear the data in the SO if it is sensitive or you can update the data the beauty is that it is controllable and has some big advantages over the 'cookie' mechanism.

               

              David.

              1 person found this helpful
              • 4. Re: does the sharedObject get destroyed when the browser is closed?
                cyber0897 Level 1

                thank you soo much guys for all your help..! after your explainations i know exactly what im doing now... thank you soo much