hi.
dont delete the elements from your array.
when you call page.destroy() method generate another array in which you
push a "true",
whenever onElementKilled is called.Check also, if the array contains as
much elements
as your children array contains.
If true, delete the whole array with childs.
possible?
dr.ache
Jiri Heitlager | dadata.org schrieb:
Hello list,
i have a page object that contains has a Array that holds
pageElements. This is a storage for elements with an iPageElement
interface.
The page object has an destroy() method. When page.destroy() is
called, it will loop trough the page.pageElements Array using an
iterator. Every iPageElement broadcasts an onElementKilled message
when is has been destroyed. When a pageElement broadcast this message,
the page need to continue in deleting the next element in the
page.pageElement Array.
The callback method onElementKilled in the page instance, searches for
the element that has been deleted and then removes it from the
page.pageElements Array. This is where i think a problem rises,
because if the page.pageElements array is updated during the process,
the index does not match the element to remove anymore. How can I
solve this potential risk?
Another question, the array that is passes into the iterator is a
reference to the pageElements Array. Does this mean, that if I delete
an element from this array from within the iterator, the
page.pageElements array is modified?
I hope my question is clear..
thank you in advance.
Jiri
Below a snippet:
private function getPageElementIterator() : Void
{
return new PageElementIterator(this.pageElements)
}
//initiated the deleting proces, by starting with the first element.
public function destroyPageElements() : Void
{
destroyElement(this.pageElements[0]);
}
private function destroyElement(element:iPageElement) : Void
{
curElement.addEventListener('onElementKilled' , this)
curElement.destroy();
}
private function onElementKilled(eventObj:Object) : Void
{
var killElement:iPageElement = eventObj.target;
var iter:PageElementIterator = this.getPageElementIterator();
while(iter.hasNext()){
var curElement:iPage = iPage (iter.next());
if(killElement == curElement) {
//deleted the element now clear the listener and continue
killElement.removeEventListener('onElementKilled' , this)
/*
* POTENTIAL RISK, if a new element is added, then the
index, does not match the right element anymore
*
* get the current index from the deleted element by
checking what
* the currentIndex of the iterator is, and remove it
from this.pageElements Array
*/
this.pageElements =
this.pageElements.splice((iter.getCurrentIndex() , 0)
//get the next element in the iterator array
if(iter.hasNext()) this.destroyElement(
iPage(iter.next()) );
delete killedElement;
break;
}
}
}
if(this.pageElements.length == 0){
trace('all page elements have been removed')
}
}
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com