I understand that ArrayCollection.addAll was added in flex sdk 3.4. I'm coding 
a simple application and I'm hitting this problem. I would like to ask if 
anyone knows what's happening:

Here's the source, just a simple mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
creationComplete="creationComplete()">
        <mx:Script>
                <![CDATA[
import mx.collections.ArrayCollection;
                private var a:Array = [
                        { key: "a", value: "b" },
                        { key: "a", value: "b" },
                        { key: "a", value: "x" },
                        { key: "a", value: "b" }
                ];
                
                private var b:Array = [
                        { key: "b", value: "c" },
                        { key: "b", value: "x" },
                        { key: "b", value: "c" },
                        { key: "b", value: "c" }
                ];
                
                private var c:Array = [
                        { key: "d", value: "x" },
                        { key: "d", value: "e" },
                        { key: "d", value: "e" },
                        { key: "d", value: "e" }
                ];
                
                [Bindable] public var xx:ArrayCollection = new 
ArrayCollection();
                
                public function creationComplete():void {
                        var i:int;
                        xx.filterFunction = filter;
                        xx.addAll(new ArrayCollection(a));
                        /*for (i = 0; i < a.length; i++) {
                                xx.addItem(a[i]);
                        }*/
                        trace("Refresh is " + xx.refresh());
                        xx.addAll(new ArrayCollection(b));
                        /*for (i = 0; i < b.length; i++) {
                                xx.addItem(b[i]);
                        }*/
                        trace("Refresh is " + xx.refresh());
                        xx.addAll(new ArrayCollection(c));
                        /*for (i = 0; i < c.length; i++) {
                                xx.addItem(c[i]);
                        }*/
                        trace("Refresh is " + xx.refresh());
                }
                        
                private function filter(item:*):Boolean {
                        if (item.value == "x") return false;
                        return true;
                }
                        
                ]]>
        </mx:Script>
        <mx:DataGrid id="dg" dataProvider="{xx}"></mx:DataGrid>
</mx:Application>

When I compile and run I get:

RangeError: Index '5' specified is out of bounds.

What I'm doing basically is to add some random array of objects into an 
ArrayCollection binded to the DataGrid. And because there is a filter function 
associated with the ArrayCollection, I call refresh() every time something is 
added. The original use case is that this is like a drop object method for the 
datagrid, so it's possible for it to be called multiple times.

I'm just curious why is this happening. Is this the desired behaviour? I'll 
look into the source code later when I'm free, but this is just to get a 
general feeling of the problem.

Reply via email to