5 Replies Latest reply on Mar 10, 2010 8:50 AM by cyber0897

    need help with sharedobjects

    cyber0897 Level 1

      hey guys, im trying to create permissions accessibility for my applications, im not sure what the most ideal solution to this is,


      on initialize of my application i call a httpservice which will return me the user id and multiple permissions as strings, i need to be able to store and access these permissions all through out my applications including components.



      im trying to create a permissions sharedObject, which i need to be able to access all throughout my application and components



      im not sure if a sharedObject is a better solution or if creating a package with variables that are permissions



      if a shared object is a better solution, then iw as wondering about how to create a new shared object, and how do i access these objects in my components?


      any help is greatly appretiated!!!


      thank you in advance

        • 1. Re: need help with sharedobjects
          David_F57 Level 5



          With shared objects all you need to do is assign the shared object data to public arrays/vars that you could then access, ideally you would have a class that is instantiated when you login that any module access's to retrieve the information.


          Also when storing 'secure' information locally you need to consider allowing the data to be retreived everytime you login or automate the login in.


          the following example is a simple login which saves info to the shared object. You would add your confirmation call to the login button then on authentication you could add all the parameters to a global array or into the shared object. If you add them to the shared object all you would need to do is call that object in any module you need access to the data.





          <?xml version="1.0" encoding="utf-8"?>

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"


             xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="app_creationCompleteHandler(event)">



          import mx.events.FlexEvent;

          public var MyID:SharedObject;


          private function updateDetails(isSelected:Boolean):void{

          if (isSelected==true)


          MyID.data.email = userID.text;

          MyID.data.password = userPass.text;

          MyID.data.keep = true;

          MyID.data.key01 = 'nul';  <= populate these values with data retreived from authentification routines.

          MyID.data.key02 = 'nul';

          MyID.data.key03 = 'nul';




          MyID.data.email = "";

          MyID.data.password = "";

          MyID.data.keep = false;

          MyID.data.key01 = 'nul';

          MyID.data.key02 = 'nul';

          MyID.data.key03 = 'nul';





          protected function app_creationCompleteHandler(event:FlexEvent):void


          MyID = SharedObject.getLocal("Login","/");

          userID.text = MyID.data.email;

          userPass.text =  MyID.data.password;

          chk_save.selected = MyID.data.keep;



          protected function button1_clickHandler(event:MouseEvent):void






          <s:TextInput  x="333" y="118" width="212" id="userID"/>

          <s:TextInput x="333" y="165" width="212" id="userPass"/>

          <s:CheckBox x="333" y="212" label="Save details" width="92" id="chk_save" selected="false"/>

          <s:Button x="457" y="208" label="Login" width="86" click="button1_clickHandler(event)"/>

          <s:Label x="333" y="102" text="User Name"/>

          <s:Label x="333" y="148" text="Password"/>


          • 2. Re: need help with sharedobjects
            cyber0897 Level 1

            hey david... thank you soo much for replying so fast... im trying to do what you sugested, but when i did the following


            import flash.net.SharedObject;
            public var sharedObj:SharedObject;
            public function init():void{
                 loginService = new HTTPService();
                 loginService.url = getlogin data in xml;
                 loginService.resultFormat = "object";
                 loginService.method = "POST";
                 loginService.useProxy = false;
                 loginService.addEventListener(ResultEvent.RESULT, getPermissions);
                 loginService.addEventListener(FaultEvent.FAULT, faultService);
            public function getPermissions(event:ResultEvent):void{
                 var permissions:Object = event.result;
                    sharedObj.data.loginData = permissions;



            i get the following error Description "Call to a possibly undefined method getLocal through a reference with static type flash.net:SharedObject. "


            is there some other library i need to include??

            • 3. Re: need help with sharedobjects
              cyber0897 Level 1

              oh, and i tried to run your application, but i wasnt able to see anything... im not sure why...

              • 4. Re: need help with sharedobjects
                David_F57 Level 5



                You declared the variable sharedObj but its never instantiated...


                you need to type sharedObj = SharedObject.getLocal("Login","/");


                I put the simple example up to see if it works for you


                http://gumbo.flashhub.net/login/   - source enabled


                Basically the first time you 'create' a shared object it only exists in memory, once you flush it it writes itself either locally or remotely, I always use local as for me I don't see the point in remote shared objects when you are already storing data in a db. In the provided example if you enter some data into the text boxes then check the save data box the information will be stored when you click the login button if You don't check the save box then any stored data is flushed. You can test this by refreshing the page after you click the login button.


                You can add what ever you want to a sharedobjects data object, the caveat is the size limit which I think defaults to 100k.




                1 person found this helpful
                • 5. Re: need help with sharedobjects
                  cyber0897 Level 1

                  yeah i actually discovered my error yesterday, and as of now the shared objects is working like a champ.. thank you soo much for your help david...