2 Replies Latest reply on Nov 2, 2006 2:29 AM by cjo_78

    Tree and TreeItemRenderer

    cjo_78
      When I drop down the first node of my tree i get the following error

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.controls.treeClasses::TreeItemRenderer/mx.controls.treeClasses:TreeItemRenderer::commi tProperties()
      at mx.core::UIComponent/validateProperties()
      at mx.managers::LayoutManager/validateClient()
      at mx.controls::List/mx.controls:List::makeRowsAndColumns()
      at mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::updateDisplayList()
      at mx.controls::List/mx.controls:List::updateDisplayList()
      at mx.controls::Tree/mx.controls:Tree::updateDisplayList()
      at mx.core::UIComponent/validateDisplayList()
      at mx.managers::LayoutManager/::validateDisplayList()
      at mx.managers::LayoutManager/::doPhasedInstantiation()
      at Function/ http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/::callLaterDispatcher2()
      at mx.core::UIComponent/::callLaterDispatcher()
      at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
      at flash.utils::Timer/flash.utils:Timer::tick()

      my code:

      <mx:Tree
      dataProvider="{myXml}"
      labelField="@datagroup"
      showRoot="false"/>

      where myXml is an XML object containing

      <root>
      <DETECT_SCORE datagroup="Detect Score" >
      <DETECT_FRAUDINDEX code="Fraud index">null</DETECT_FRAUDINDEX>
      <DETECT_DET_CRED_SCR code="Credit score">null</DETECT_DET_CRED_SCR>
      <DETECT_AUTHINDEX code="Authenticate index">null</DETECT_AUTHINDEX>
      <DETECT_APP_SCR code="Application score">null</DETECT_APP_SCR>
      </DETECT_SCORE>
      <DEL1 datagroup="LOCATE">
      </DEL1>
      <DEL10000 datagroup="Detect data exists indicator">
      <DET-C-001 code="Detect data exists indicator">Y</DET-C-001>
      </DEL10000>
      <DEL10500 datagroup="Fra ....etc

      Has anyone else had this problem, or can anyone suggest a solution?

      Thanks
        • 1. Re: Tree and TreeItemRenderer
          peterent Level 2
          I'm not exactly sure what the specific problem is without running the code, but I see some potential/possible problems.

          The Tree likes things to be very uniform: every node in the XML having the same name and the same attribute. You have some nodes called "DETECT_SCORE" and other nodes called DETECT_FRAUDINDEX, for example. Some nodes have the attribute datagroup, others do not. The Tree will be confused without some more direction.

          You should have a labelFunction to help it out. The labelFunction will be given a node. You can ask the node for its localName and then determine which attribute should be the label.

          Here's a sample labelFunction:

          private function treeLabel( item:Object ) : String
          {
          var node:XML = XML(item);
          if( node.localName() == "DETECT_SCORE" )
          return node.@datagroup;
          else if( node.localName() == "DETECT_FRAUDINDEX")
          return node.@code;
          else ...
          }
          • 2. Re: Tree and TreeItemRenderer
            cjo_78 Level 1
            Thanks, I'll give that a try.
            I know the XMLs a bit odd, but it's coming from an external source, and I'm trying to avoid having to process it.