1 Reply Latest reply on Nov 3, 2009 6:35 AM by SusieIre

    inline component error

    SusieIre

      Hi,

       

      I have a main mxml file calling a mxml file to create a drop down LOV. However, when loading the form I get the error #1009

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at vidcomponents::QueryLOV/setSelectedItem()[M:\MSU\DevProjectCode\Flex\Workspaces\ucd_epms\ src\vidcomponents\QueryLOV.mxml:122].

       

      The line in question is this -

      localData = data[

      this.FieldName]; I can't find the problem so help would be very much appreciated , I've pasted some more code below. Thanks.

       

       

      --code to call LOV

       

      <mx:AdvancedDataGridColumn width="120" headerText="Action" dataField="EPST_CODE"

      editable="

      true" sortable="false" rendererIsEditor="true" editorDataField="Value">

       

      <mx:itemRenderer>

       

      <mx:Component>

       

      <comp:QueryLOV DataProvider="{outerDocument.lookup('ACTSTATUSSCH')}" styleName="field" FieldName="EPST_CODE"/>

       

      </mx:Component>

       

      </mx:itemRenderer>

       

      </mx:AdvancedDataGridColumn>

       

       

       

      - LOV File

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

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

      <mx:HBox

       

       

      xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="vidcomponents.*

      "

      horizontalGap="

       

      0" verticalGap="0

      "

      verticalScrollPolicy="

       

      off" horizontalScrollPolicy="off

      "

      dataChange="setSelectedItem(event)"

      creationComplete="initComponent()"

      backgroundColor="

       

      #E5E4E4"

      >

       

       

       

       

      <mx:Script>

      <![CDATA[

       

       

      import

      mx.utils.StringUtil;

       

       

      import

      mx.controls.DataGrid;

       

       

      import

      mx.collections.ArrayCollection;

       

       

      import

      mx.controls.Alert;

       

       

      import

      mx.managers.PopUpManager;

       

       

      import

      mx.utils.ObjectUtil;

       

      [

       

      Bindable] public var

      DataProvider:ArrayCollection;

      [

       

      Bindable] public var

      ac:ArrayCollection;

      [

       

      Bindable] public var autoPopup:Boolean=true

      ;

      [

       

      Bindable] public var showAllItems:Boolean=false

      ;

      [

       

      Bindable] public var allItemsLabel:String = "-- All --"

      ;

       

       

       

      public var

      excludeCodes:String;

       

       

      public var

      excludeArray:Array;

       

       

       

      public var

      FieldName:String;

       

       

       

      public var UniqueIndicator:Boolean = false

      ;

       

       

      public var

      DG:DataGrid;

       

       

      public var showDescription:Boolean = true

      ;

       

       

       

      private var

      _val:String;

       

       

      private var

      _desc:String;

       

       

       

      private function initComponent():

      void

      {

      descfield.width =

       

      this.width - this

      .lovbutton.width;

      descfield.height =

       

      this

      .height;

       

       

       

       

       

      if(ac==null

      )

      ac = ObjectUtil.copy(DataProvider)

       

      as

      ArrayCollection;

       

       

       

       

       

      if(showAllItems==true

      )

      {

      ac.addItemAt({DATA:

       

      "*"

      , LABEL:allItemsLabel}, 0);

      _val =

       

      "*"

      ;

      }

       

       

       

      if ((excludeArray!=null) && (excludeCodes==null

      ))

      {

       

       

      for (var

      i:Number=0; i<excludeArray.length; i++)

      excludeCodes +=

       

      ',' + excludeArray[i] + ','

      ;

      }

       

      sync();

      }

       

       

       

      public function set Value(val:String):void

      {

      _val = val;

      sync();

      }

       

       

       

      public function get

      Value():String

      {

       

       

      return

      _val;

      }

       

       

       

      public function set Description(desc:String):

      void

      {

      _desc = desc;

      }

       

       

       

      public function get

      Description():String

      {

       

       

      return

      _desc;

      }

       

       

       

      private function

      findDescription(dataval:String):String

      {

       

       

       

      if (ac == null

      )

       

       

      return null

      ;

       

       

       

      for (var

      i:Number=0; i<ac.length; i++)

      {

       

       

      if

      (ac[i].DATA == dataval)

       

       

      return

      ac[i].LABEL;

      }

       

       

       

      return

      dataval;

      }

       

       

       

      private function sync():

      void

      {

      _desc = findDescription(_val);

       

       

       

      this

      .valuefield.text = _val;

       

       

      if(this.showDescription==true

      )

       

       

      this

      .descfield.text = _desc;

       

       

      else

       

       

      this

      .descfield.text = _val;

       

      }

       

       

       

      private function setSelectedItem(event:Event):

      void

      {

       

       

      var

      localData:String;

       

       

       

      if (this.FieldName == null

      ){

       

       

      if (data != null

      )

      localData = data.toString();

      }

       

       

      else

      {

       

      localData = data[

       

      this

      .FieldName].toString();

      _val = localData;

      sync();

       

      }

      }

       

       

       

       

       

      public function SetContents(code:String, desc:String):

      void

      {

       

      _val = code;

      _desc = desc;

       

       

      if (this.FieldName == null

      ){

      data = code;

      }

       

       

      else

      {

      data[

       

      this

      .FieldName] = code;

      }

      sync();

      }

       

       

       

      private function clickField():

      void

      {

       

       

      if (autoPopup==true

      )

      showPopup();

      }

       

       

       

      private function showPopup():

      void

      {

       

       

      var dialog:QueryPopup = QueryPopup(PopUpManager.createPopUp(this, QueryPopup, true

      ));

      dialog.callingControl =

       

      this

      ;

      dialog.DataProvider =

       

      this

      .ac;

       

       

      PopUpManager.centerPopUp(dialog);

       

       

       

      if

      ((dialog.x + dialog.width)> parentApplication.width)

      dialog.x = parentApplication.width - dialog.width;

       

       

       

      if

      ((dialog.y)<0)

      dialog.y = 0;

       

      }

       

      ]]>

       

       

      </mx:Script>

       

       

       

      <mx:TextInput id="descfield" editable="false" click="clickField()"

      />

       

       

      <mx:Button id="lovbutton" enabled="{this.enabled}" visible="{this.enabled}" click="showPopup()" icon="@Embed(source='../assets/images/up.png')" width="{this.enabled?25:0}"

      />

       

       

      <mx:TextInput id="valuefield" change="Value = this.valuefield.text" x="0" y="0" width="1" focusRect="null" visible="false"

      />

        • 1. Re: inline component error
          SusieIre Level 1

          Hi,

           

          Sorry my message may be a bit too long , the main code that's giving me the error is the function

           

           

           

           

           

           

           

           

           

          private function setSelectedItem(event:Event):

          void

          {

           

           

          var

          localData:String;

           

           

           

          if (this.FieldName == null

          ){

           

           

          if (data != null

          )

          localData = data.toString();

          }

           

           

          else

          {

           

          localData = data[t

          his.FieldName].toString();

          _val = localData;

          sync();

           

          }

          }

           

          I would really appreciate some help on this as am a beginner and quite stuck.

           

          thanks a mil