1 Reply Latest reply on Jun 19, 2007 1:54 PM by ntsiii

    Null object reference

    oxide_reaction Level 1
      I've been trying to figure this out for several hours and would really appreciate some help.

      the program won't load because it says that loading the text from the 3 input fields is a null object reference. the program won't load, it just gives me the error and I can't seem to see how to fix it.

      Here's the code:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="vertical">

      <mx:Script>
      <![CDATA[
      /////////////////////// here's the problem/////////////////////
      public var theData:XML =
      <entry>
      <title>{addTitleInput.text}</title>
      <body>{addBodyInput.text}</body>
      <date>{addDateInput.text}</date>
      </entry>;
      ]]>
      </mx:Script>

      <mx:HTTPService id="userRequest" url="the/path/to/the/script.php" useProxy="false" method="POST">
      <mx:request xmlns="">
      <data>{theData}</data>
      </mx:request>
      </mx:HTTPService>

      <mx:Panel id="addEntry" label="Add Entry" title="Add Entry" showEffect="Iris" hideEffect="Iris" width="500">
      <mx:VBox width="100%">
      <mx:Form id="addForm" width="100%">
      <mx:FormItem label="Title">
      <mx:TextInput id="addTitleInput"/>
      </mx:FormItem>
      <mx:FormItem label="Body" width="100%">
      <mx:RichTextEditor id="addBodyInput" height="350" width="100%">
      </mx:RichTextEditor>
      <mx:DateField id="addDateInput" showEffect="Zoom"/>
      </mx:FormItem>
      <mx:HBox width="100%" horizontalAlign="center" height="40" verticalAlign="bottom">
      <mx:Button label="Submit" click="userRequest.send()"/>
      <mx:Button label="Cancel"/>
      </mx:HBox>
      </mx:Form>
      </mx:VBox>
      </mx:Panel>
      </mx:Application>


      Thanks,

      Josh
        • 1. Re: Null object reference
          ntsiii Level 3
          Yes, you cannot do that work outside of a function. This is because of the way mxml is generated into AS and compiled.

          Declare the variable in instance scope as you have it, but do the assignment in a function called by the Application initialize or creationComplete event,

          Tracy