Actually, you don't want to do either option. You want to implement
getChildren to return a separate array collection for each collection of
children. This is because the individual sets of children are tracked
an managed by the tree so you can't reuse one collection instance, and
you should not return different instances for the same set of children,
otherwise one part of the tree code will make changes that some other
part will not notice. Look at the default descriptor and see that it
caches the AC instances per node/children set
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of florian.salihovic
Sent: Thursday, November 29, 2007 4:27 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] ListCollectionView#removeAll wants to dispatch
undefined
Currently i write a lil' component to display class hierachies. I wrote
my own
TreeDataDescriptor. SInce i work with my own class-, packages- and
interface-descriptor
classes to describe the structure, i encapsule some ArrayCollection. In
order to display the
structures in a tree, i need to melt them together in one
ArrayCollection. So far so good...
Since i want not to create a new ArrayCollection everytime the
ITreeDataDescriptor#getChildren is called, i thought to create one
ArrayCollection and
remove all items when the function is called. I thought it would be ok
to create a new field
(typed: ArrayCollection) for the class. But actually the forces my
component to crash.
Here's the code:
precode
public function getChildren(node:Object,
model:Object=null):ICollectionView {
trace(this._className+#getChildren);
try {
if(node is PackageDescriptor) {
this._children.sort = null;
/*try {
this._children.removeAll();
this._children.refresh();
} catch (e:Error) {
trace(Error: +e.message)
} catch (e1:StackOverflowError) {
trace(StackOverflowError: +e1.message);
} catch (e2:CollectionViewError) {
trace(CollectionViewError: +e2.message);
} catch (e3:ArgumentError) {
trace(ArgumentError: +e2.message);
}*/
trace(\tnode.className: +PackageDescriptor(node).className);
this._children = new ArrayCollection();
var packageDescriptor:PackageDescriptor = PackageDescriptor(node);
for (var i:uint = 0; ipackageDescriptor.packages.length; i++) {
this._children.addItem(PackageDescriptor(packageDescriptor.packages.getI
temAt(i)));
}
for (var j:uint = 0; jpackageDescriptor.classes.length; j++) {
this._children.addItem(ClassDescriptor(packageDescriptor.classes.getItem
At(j)));
}
for (var k:uint = 0; kpackageDescriptor.interfaces.length; k++) {
this._children.addItem(InterfaceDescriptor(packageDescriptor.interfaces.
getItemAt(k)));
}
/*for (var l:uint = 0; lthis._children.length; l++) {
trace(\t\t+l+: +this._children.getItemAt(l).name);
}*/
return this._children;
}
} catch (e:Error) {
trace(Error: +e.message)
} catch (e1:StackOverflowError) {
trace(StackOverflowError: +e1.message);
} catch (e2:CollectionViewError) {
trace(CollectionViewError: +e2.message);
} finally {
return _children;
}
}/code/pre
So why is it at this point wrong to call removeAll to remove all
references from the
ArrayCollection instead of creating a new ArrayCollection all the time?
The code above
compiles. If i uncomment the first try/ctach statement, the application
crashes.