I am trying to implement code to move items up and down in an
AdvancedDataGrid. When I repeat the "move up" or "move down" action
multiple times in a row I get the error below. I don't get it every
time but it will come here and there...pretty frequently. Sometimes I
can click 2, 3, even 4 times without getting an error then I click again
and there it is.
See below for the 3 functions which implement the "move up" feature.
I have tried commenting out the last line in the changeNodeHierarchy
function which re-selects the moved item. This does seem to resolve the
error but I can't be sure because the occurrence of the error is not
consistent.
Can someone tell me what I am doing wrong?
Code
public function changeNodeHierarchy(dataGrid:AdvancedDataGrid):void{
var oldSelection:Array = dataGrid.selectedItems.slice();
var selection:Array = DataGridUtil.getSortedSelectedItems(dataGrid);
for each (var node:Object in selection) {
moveUpNode(dataGrid, node); }
dataGrid.selectedItems = oldSelection;}
public static function moveUpNode(dataGrid:AdvancedDataGrid,
node:Object):void{ var view:IHierarchicalCollectionView =
dataGrid.hierarchicalCollectionView; var children:IList =
DataGridUtil.getChildren(dataGrid, view.getParentItem(node)); var
indexInParent:int = children.getItemIndex(node); if (indexInParent !=
0) moveNode(dataGrid, node, view.getParentItem(node),
indexInParent - 1);}
private static function moveNode(dataGrid:AdvancedDataGrid, node:Object,
newParent:Object, index:int):void{ var
view:IHierarchicalCollectionView = dataGrid.hierarchicalCollectionView;
if (view.sort == null) { var parent:Object =
view.getParentItem(node); view.removeChild(parent, node);
view.addChildAt(newParent, node, index); }}
ErrorError: Bookmark no longer valid. at
ListCollectionViewCursor/seek()[E:\dev\4.x\frameworks\projects\framework\
\src\mx\collections\ListCollectionView.as:2410] at
mx.collections::HierarchicalCollectionViewCursor/get
current()[E:\dev\4.x\frameworks\projects\datavisualization\src\mx\collec\
tions\HierarchicalCollectionViewCursor.as:220] at
mx.collections::HierarchicalCollectionViewCursor/collectionChangeHandler\
()[E:\dev\4.x\frameworks\projects\datavisualization\src\mx\collections\H\
ierarchicalCollectionViewCursor.as:1143] at
flash.events::EventDispatcher/dispatchEventFunction() at
flash.events::EventDispatcher/dispatchEvent() at
mx.collections::HierarchicalCollectionView/nestedCollectionChangeHandler\
()[E:\dev\4.x\frameworks\projects\datavisualization\src\mx\collections\H\
ierarchicalCollectionView.as:1589] at
flash.events::EventDispatcher/dispatchEventFunction() at
flash.events::EventDispatcher/dispatchEvent() at
mx.collections::ListCollectionView/dispatchEvent()[E:\dev\4.x\frameworks\
\projects\framework\src\mx\collections\ListCollectionView.as:1024] at
mx.collections::ListCollectionView/removeItemsFromView()[E:\dev\4.x\fram\
eworks\projects\framework\src\mx\collections\ListCollectionView.as:1681]
at
mx.collections::ListCollectionView/listChangeHandler()[E:\dev\4.x\framew\
orks\projects\framework\src\mx\collections\ListCollectionView.as:1292]
at flash.events::EventDispatcher/dispatchEventFunction() at
flash.events::EventDispatcher/dispatchEvent() at
mx.collections::XMLListAdapter/removeItemAt()[E:\dev\4.x\frameworks\proj\
ects\framework\src\mx\collections\XMLListAdapter.as:431] at
mx.collections::ListCollectionView/removeItemAt()[E:\dev\4.x\frameworks\\
projects\framework\src\mx\collections\ListCollectionView.as:762] at
ListCollectionViewCursor/remove()[E:\dev\4.x\frameworks\projects\framewo\
rk\src\mx\collections\ListCollectionView.as:2330] at
mx.collections::HierarchicalCollectionView/removeChild()[E:\dev\4.x\fram\
eworks\projects\datavisualization\src\mx\collections\HierarchicalCollect\
ionView.as:731]