views:

106

answers:

2

I'm working on a Flex 3 project, and I'm using a pair of XMLListCollection(s) to manage a combobox and a data grid.

The combobox piece is working perfectly. The XMLListCollection for this is static. The user picks an item, and, on "change", it fires off an addItem() to the second collection. The second collection's datagrid then displays the updated list, and all is well.

The datagrid, however, is editable. A further complication is that I have another event handler bound to the second XMLLIstCollection's "change" event, and in that handler, I do make additional changes to the second list. This essentially causes an infinite loop (a stack overflow :D ), of the second lists "change" handler.

I'm not really sure how to handle this. Searching has brought up an idea or two regarding AutoUpdate functionality, but I wasn't able to get much out of them. In particular, the behavior persists, executing the 'updates' as soon as I re-enable, so I imagine I may be doing it wrong. I want the update to run, in general, just not DURING that code block.

Thanks for your help!

A: 

Trying to bind the behaviour to a custom event rather than the CHANGE event.

I.e. do what you are doing now, but dispatch and handle a custom event to do the work.

Gregor Kiddie
A: 

Have you considered using callLater? Does direct manipulation of XMLListCollection's source XMLList have the same results? Have you considered something like:

private function changeHandler( event:Event ):void
{
    event.target.removeEventListener( event.type, changeHandler );

    // your code here.

    event.target.addEventListener( event.type, changeHandler );
}
Christopher W. Allen-Poole
This looks promising. I'm eager to try it out. Thanks
reidLinden