What is BookMark Error in flex and how it is resolved?

var res:ArrayCollection = event.result as  ArrayCollection;
if(folderObj.children != null)
       folderObj.children.addItem(res[i]);

In the above code, i am getting the following error.

Error: Bookmark no longer valid.
      at ListCollectionViewCursor/seek()
      at mx.collections::HierarchicalCollectionViewCursor/get current()
      at mx.collections::HierarchicalCollectionViewCursor/collectionChangeHandler()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.collections::HierarchicalCollectionView/nestedCollectionChangeHandler()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.collections::ListCollectionView/dispatchEvent()
      at mx.collections::ListCollectionView/addItemsToView()
      at mx.collections::ListCollectionView/listChangeHandler()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.collections::ArrayList/internalDispatchEvent()
      at mx.collections::ArrayList/addItemAt()
      at mx.collections::ListCollectionView/addItemAt()
      at mx.collections::ListCollectionView/addItem()
      at com.zetainteractive.model.managers::ListManager/sampleData()
      at com.cynergysystems.tango::GenericResponder/result()
      at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()
      at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()
      at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
      at mx.rpc::Responder/result()
      at mx.rpc::AsyncRequest/acknowledge()
      at NetConnectionMessageResponder/resultHandler()
      at mx.messaging::MessageResponder/result()
vmaradaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zzynxSoftware engineerCommented:
What is the type of "folderObj.children"? A ListCollectionView I suppose?

Try replacing

var res:ArrayCollection = event.result as  ArrayCollection;
if(folderObj.children != null)
       folderObj.children.addItem(res[i]);

by

var res:ArrayCollection = event.result as  ArrayCollection;
if(folderObj.children != null) {
       var lcv:ListCollectionView = folderObj.children as ListCollectionView;
       lcv.disableAutoUpdate();
       lcv.addItem(res[i]);
       lcv.enableAutoUpdate();
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vmaradaAuthor Commented:
folderObj.children is an ArrayCollection.
0
zzynxSoftware engineerCommented:
>> folderObj.children is an ArrayCollection
Good! Since an ArrayCollection extends ListCollectionView:

var res:ArrayCollection = event.result as  ArrayCollection;
if(folderObj.children != null) {
       var ac:ArrayCollection = folderObj.children as ArrayCollection;
       ac.disableAutoUpdate();
       ac.addItem(res[i]);
       ac.enableAutoUpdate();
}
0
Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

vmaradaAuthor Commented:
folderObj.children.enableAutoUpdate();

same error is being shown in the above line.

Error: Bookmark no longer valid.
      at ListCollectionViewCursor/seek()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:2048]
      at mx.collections::HierarchicalCollectionViewCursor/get current()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\collections\HierarchicalCollectionViewCursor.as:198]
      at mx.controls.advancedDataGridClasses::AdvancedDataGridBase/createRow()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\advancedDataGridClasses\AdvancedDataGridBase.as:1629]
      at mx.controls.advancedDataGridClasses::AdvancedDataGridBase/makeRowsAndColumns()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\advancedDataGridClasses\AdvancedDataGridBase.as:892]
      at mx.controls::AdvancedDataGridBaseEx/makeRowsAndColumns()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGridBaseEx.as:1918]
      at mx.controls::AdvancedDataGrid/makeRowsAndColumns()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGrid.as:7169]
      at mx.controls.listClasses::AdvancedListBase/makeRowsAndColumnsWithExtraRows()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\listClasses\AdvancedListBase.as:1231]
      at mx.controls.listClasses::AdvancedListBase/updateDisplayList()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\listClasses\AdvancedListBase.as:3501]
      at mx.controls::AdvancedDataGridBaseEx/updateDisplayList()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGridBaseEx.as:1778]
      at mx.controls::AdvancedDataGrid/updateDisplayList()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\AdvancedDataGrid.as:6007]
      at mx.controls.listClasses::AdvancedListBase/validateDisplayList()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\controls\listClasses\AdvancedListBase.as:3072]
      at mx.managers::LayoutManager/validateDisplayList()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:622]
      at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:695]
      at Function/http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
      at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.collections::HierarchicalCollectionView/nestedCollectionChangeHandler()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\collections\HierarchicalCollectionView.as:1202]
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.collections::ListCollectionView/dispatchEvent()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:833]
      at mx.collections::ListCollectionView/addItemsToView()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:931]
      at mx.collections::ListCollectionView/listChangeHandler()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1051]
      at mx.collections::ListCollectionView/handlePendingUpdates()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:1210]
      at mx.collections::ListCollectionView/enableAutoUpdate()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\collections\ListCollectionView.as:370]
      at com.zetainteractive.model.managers::ListManager/sampleData()[D:\ZetaMail5\zetamail_flex\src\com\zetainteractive\model\managers\ListManager.as:2807]
      at com.cynergysystems.tango::GenericResponder/result()[D:\ZetaMail5\zetamail_flex\src\com\cynergysystems\tango\GenericResponder.as:22]
      at mx.rpc::AsyncToken/http://www.adobe.com/2006/flex/mx/internal::applyResult()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncToken.as:199]
      at mx.rpc.events::ResultEvent/http://www.adobe.com/2006/flex/mx/internal::callTokenResponders()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\events\ResultEvent.as:172]
      at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractOperation.as:193]
      at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
      at mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
      at mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
      at NetConnectionMessageResponder/resultHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:515]
      at mx.messaging::MessageResponder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\MessageResponder.as:199]
0
zzynxSoftware engineerCommented:
What if you remove the enableAutoUpdate() and just keep the disableAutoUpdate()?
0
vmaradaAuthor Commented:
The objects are not getting added to the folderObj, if i remove enableAutoUpdate().
0
zzynxSoftware engineerCommented:
>> The objects are not getting added to the folderObj, if i remove enableAutoUpdate().
Well, they are but the view doesn't show them due to disableAutoUpdate() call as the Flex help states:

Prevents changes to the collection itself and items within the collection from being dispatched by the view. Also prevents the view from updating the positions of items if the positions change in the collection.

But the above is followed by:
The changes will be queued and dispatched appropriately after enableAutoUpdate is called.
The disableAutoUpdate method acts cumulatively; the same number of calls to enableAutoUpdate  are required for the view to dispatch events and refresh.

So, the question is: when calling enableAutoUpdate() again without having the problem...
0
vmaradaAuthor Commented:
how to find that ....by calling enableAutoUpdate() will not cause the problem....
0
zzynxSoftware engineerCommented:
It's clear that calling disableAutoUpdate() helps in avoiding the error.
Apparently calling enableAutoUpdate() is also needed if you want the view to be updated according to the changes.
But if you do at that point, you get the same error.
Maybe you should call it "later"...

Could you try this:

var res:ArrayCollection = event.result as  ArrayCollection;
if(folderObj.children != null) {
       folderObj.children.disableAutoUpdate();
       folderObj.children.addItem(res[i]);
       callLater(
           public function():void {
                folderObj.children.enableAutoUpdate();
       });
}
0
vmaradaAuthor Commented:
Compilation error is showing in the above code at callLater saying that "call to a possibly undefined method callLater".
0
zzynxSoftware engineerCommented:
Well, callLater() is a method that can be called on all objects that inherit from the UIComponent class.
I don't know the context of your code snippet.
I would suggest you call it on the "view class/control" that displays that collection.
0
vmaradaAuthor Commented:
Here the Problem is the code is in the Action Script File. How to deal with that in AS file
0
zzynxSoftware engineerCommented:
>> the code is in the Action Script File
I was already assuming that, yes.
My comment stays valid.

If you simply wrote callLater() in fact you call it on this, being the instance of the class your AS file represents.
That class should inherit from UIComponent.
0
vmaradaAuthor Commented:
Addressed partiakl fix
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Flex

From novice to tech pro — start learning today.