1 Reply Latest reply on Mar 6, 2011 8:05 AM by bmleite

    Error message Help

    Whitetimer Level 1

      Hi All

       

      I am getting this error and cant figure out why

      Quote
      TypeError: Error #1009: Cannot access a property or method of a null object reference.

      This is the code i have
      Code:
      // event handlers -------------------------------------------
              private function loadTXT(event:Event):void
              {
                  // Create the URLLoader instance to be able to load data
                  var loader:URLLoader = new URLLoader();
                  // Attempt to load some data
                  loader.load(new URLRequest('Data/Text/aboutintro.txt'));
                  loader.addEventListener(Event.COMPLETE, onComplete);
              }

       

              private function onComplete(event:Event):void
              {
                  //Alert.show( "The data has successfully loaded" )
                  var myData:String = new String(event.target.data);
                  aboutTXT.text = myData;
              }

      Any suggestions please ?

       

      Many Thanks

        • 1. Re: Error message Help
          bmleite Level 1

          Hi,

           

          I would say that the problem is on the line:

                aboutTXT.text = myData;

           

          Probably the "aboutTXT" component is not yet created. Try to check it by doing this:

                private function onComplete(event:Event):void
                {
                   //Alert.show( "The data has successfully loaded" )
                   var myData:String = new String(event.target.data);
                   if (aboutTXT != null) {
                       aboutTXT.text = myData;
                   }
                } 
          

           

          If the error disappears then you have found the problem. If that's the case, try to call the "loadTXT()" only after the "creationComplete" event has been dispatched by the component.

           

          The problem can also be on the line:

               var myData:String = new String(event.target.data);
          

           

          Where for some reason the target (from the event.target) can be set to null. The best way to check this is by running the app in debug mode, or with:

               trace(event.target);

           

          Let me know it this helps.