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:
<pre><code>
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; 
i<packageDescriptor.packages.length; i++) {
                                
this._children.addItem(PackageDescriptor(packageDescriptor.packages.getItemAt(i)));
                        }
                        for (var j:uint = 0; 
j<packageDescriptor.classes.length; j++) {
                                
this._children.addItem(ClassDescriptor(packageDescriptor.classes.getItemAt(j)));
                        }
                        for (var k:uint = 0; 
k<packageDescriptor.interfaces.length; k++) {
                                
this._children.addItem(InterfaceDescriptor(packageDescriptor.interfaces.getItemAt(k)));
                        }
                        /*for (var l:uint = 0; l<this._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.

Reply via email to