views:

3287

answers:

3

I have a method to add an XML node structure to the currenltly selected tree node.

This appends the xml, and opens the parent node to display the newly added node.

I then select the node by setting the selectedItem of the tree.

I have an editing form that updates its values on the tree change event. When I set the selectedItem in this method, The node is selected correctly but the change event never fires (thus the editor doesnt update). I have tried to call it in a call later block to no avail.

Is there a way I can force the tree to dispatch a change event at this point?

public function addSelected(node:XML):void{

   tree_expandItem(false);    

   var selectedItem:XML = tree.selectedItem as XML;

   selectedItem.appendChild(node);

   tree_expandItem(true);

   callLater(function():void { tree.selectedItem = node; } ); 

  }

To extend this question in a general sort of way - I would have thought that changing the selectedItem of the tree would result in a change event anyway? Or is a change only considered a change if the user makes it?

+2  A: 

Is there a way I can force the tree to dispatch a change event at this point?

Use the dispatchEvent() method. Thanks James!

dirkgently
it's actually the dispatchEvent() method ;)
James Hay
Right, thanks James.
dirkgently
This would also work, thanks
Andy Johnston
+1  A: 

You could move the logic that is currently in your change event handler to a separate function, and then call that function directly:

private function changeHandler(event:ListEvent):void
{
    doChangeLogic();
}

private function doChangeLogic():void
{
    //statements
}

public function addSelected(node:XML):void
{
    tree_expandItem(false);                         

    var selectedItem:XML = tree.selectedItem as XML;

    selectedItem.appendChild(node);

    tree_expandItem(true);

    callLater(function():void { tree.selectedItem = node; } );

    doChangeLogic();
}
Eric Belair
Yep that will work for sure.. foolish me.. looking for a complex answer to a simple question..
Andy Johnston
Awesome! Glad I could help!
Eric Belair
A: 

Andy,

The same issue am facing now... could you please elaborate the logic to dispatch the change eventfor tree.

Regards, Sathish

sathishkumar