1 Reply Latest reply on Feb 14, 2011 4:54 PM by sky858

    SharedObject Error

    sky858 Level 1

      I created a shared object and an event listener that triggers it to save.  The problem I am having is that the sharedObject only works sometimes.  When it doesnt work I get error 1009 (cannot access a property or method of a null object) during dubug.  I have searched around and done everything I can think of, but I can't figure out what I am doing wrong.  I have posted a slightly simplified version of my code below.  Does anyone know what I am doing wrong?  I am new to this so the more detail, the better.

      Thank you for the help!

        • 1. Re: SharedObject Error
          sky858 Level 1

          Here is the code.  The null error is at so.data.g2 = g2.text

          Thanks again for the help

           

          <?xml version="1.0" encoding="utf-8"?>
          <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                                  xmlns:s="library://ns.adobe.com/flex/spark"
                                  xmlns:t="MasterPlanAlt/src/PersistentTextInput.as"
                                  xmlns:mx="library://ns.adobe.com/flex/mx"  showStatusBar="false" backgroundColor="#000000" xmlns:ns1="*"  xmlns:events="qnx.events.*">
               <fx:Style source="MasterPlanAlt.css"/>
               <fx:Script>
                   <![CDATA[
                       import flash.events.Event;
                       import mx.events.FlexEvent;
                       import flash.net.SharedObject;
                       [Bindable]
                       private var so:SharedObject;
                       [Bindable]
                       private var text_g1:String;
                       [Bindable]
                       private var text_g2:String;
                       [Bindable]
                       private var text_g3:String;
                       [Bindable]
                       private var text_g4:String;
                       [Bindable]
                       private var text_g5:String;
                       [Bindable]
                       private var text_g6:String;
                       [Bindable]
                       private var text_g7:String;
                       [Bindable]
                       private var text_g8:String;
                       [Bindable]
                       private var text_g9:String;
                       [Bindable]
                       private var text_g10:String;
                       private function onDeactivate(e:Event):void
                       {
                           so = SharedObject.getLocal("userData");
                           so.data.g1 = g1.text;
                           so.data.g2 = g2.text;
                           so.data.g3 = g3.text;
                           so.data.g4 = g4.text;
                           so.data.g5 = g5.text;
                           so.data.g6 = g6.text;
                           so.flush();
                       }
                   ]]>
               </fx:Script>
               <s:creationComplete>
                   <![CDATA[
                   so = SharedObject.getLocal("userData");
                   {
                       text_g1 = so.data.g1;
                       text_g2 = so.data.g2;
                       text_g3 = so.data.g3;
                       text_g4 = so.data.g4;
                       text_g5 = so.data.g5;
                       text_g6 = so.data.g6;
                       this.addEventListener(Event.DEACTIVATE, onDeactivate);
                   }
               ]]>
               </s:creationComplete>


               <mx:ViewStack x="10" y="140" id="viewstack1" width="1001" height="458">
                   <s:NavigatorContent label="1" width="100%" height="100%" id="nc1">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g1"  text="{text_g1}"/>
                       </s:BorderContainer>  
                   </s:NavigatorContent>
                   <s:NavigatorContent label="2" width="100%" height="100%" fontSize="18" id="nc2">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g2"  text="{text_g2}"/>
                       </s:BorderContainer>
                   </s:NavigatorContent>
                   <s:NavigatorContent label="3" width="100%" height="100%">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g3"  text="{text_g3}"/>
                       </s:BorderContainer>
                   </s:NavigatorContent>
                   <s:NavigatorContent label="4" width="100%" height="100%">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g4"  text="{text_g4}"/>
                       </s:BorderContainer>
                   </s:NavigatorContent>
                   <s:NavigatorContent label="5" width="100%" height="100%">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g5"  text="{text_g5}"/>
                       </s:BorderContainer>
                   </s:NavigatorContent>
                   <s:NavigatorContent label="6" width="100%" height="100%">
                       <s:BorderContainer x="10" y="28" width="981" height="105" backgroundColor="#000000">
                           <s:TextArea x="10" y="10" height="83" width="922"  contentBackgroundColor="#CCCCCC" fontSize="14" id="g6"  text="{text_g6}"/>
                       </s:BorderContainer>
                   </s:NavigatorContent>
               </mx:ViewStack>
               <mx:ToggleButtonBar x="10" y="91" dataProvider="{viewstack1}" width="1001" height="41" color="#000000" fontSize="14">
               </mx:ToggleButtonBar>
          </s:WindowedApplication>