0 Replies Latest reply on Nov 25, 2007 4:01 PM by powerflex

    isBranch=true infinite loop

    powerflex Level 1
      Hi everyone,

      Been working on an application that uses the tree control - a source of endless frustration... If anyone has an idea on this issue please help...

      I allow users to add a folder to the tree dynamically using isBranch=true (AFAIK its the proper way according to flex2 devguide page 200). The tree item adds but if you expand it then collapse and re-expand its parent the app goes in endless loop with this error:
      TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.controls::Tree/private::getOpenChildrenStack()
      at mx.controls::Tree/private::getOpenChildrenStack()
      at mx.controls::Tree/private::buildUpCollectionEvents()
      at mx.controls::Tree/ http://www.adobe.com/2006/flex/mx/internal::onTweenEnd()
      at mx.effects::Tween/endTween()
      at mx.effects::Tween/ http://www.adobe.com/2006/flex/mx/internal::doInterval()
      at mx.effects::Tween$/private::timerHandler()
      at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
      at flash.utils::Timer/flash.utils:Timer::tick()

      Heres the code:

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" applicationComplete="init();">
      <mx:Script><![CDATA[

      private function init():void{
      tree.dataProvider = new XMLList( xml.node);
      tree.callLater(expand);
      }

      private function expand():void{
      tree.selectedIndex = 0;
      tree.expandItem(tree.selectedItem, true);
      tree.expandChildrenOf(tree.selectedItem, true);
      }


      private function doIt():void{
      var n_xml:XML = <node label='Garr!' isBranch='true'/>;
      for each( var x:XML in xml.descendants() ){
      if( x.@type == 'Ones' ){
      var o:* = tree.openItems;
      x.appendChild(n_xml);
      tree.dataProvider = new XMLList( xml.node );
      tree.openItems = o;
      return;
      }
      }

      }
      ]]></mx:Script>

      <mx:XML source="tree.xml" id="xml"/>

      <mx:Panel title="Garrrrr Tree!" width="100%" height="100%">

      <mx:Tree id="tree" labelField="@label" width="100%" height="100%"/>

      <mx:Button label="Click" click="doIt();"/>
      </mx:Panel>
      </mx:Application>

      here's the data source:

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

      <node label="Ones" type="Ones">
      <node label="One Hundred" id="100" type="One"/>
      <node label="One Thousand" id="104" type="One"/>
      <node label="One Million" id="343" type="One"/>
      </node>

      <node label="Twos" type="Twos">
      <node label="Two Hundred" id="200" type="Two"/>
      <node label="Two Thousand" id="204" type="Two"/>
      <node label="Two Million" id="243" type="Two"/>
      </node>

      </node>

      </node>