The docs are wrong if that's what it says.  Only addItemAt(length())
will allow it to grow.

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of Jurgen Beck
Sent: Monday, May 21, 2007 1:38 PM
To: [email protected]
Subject: Re: {Disarmed} [flexcoders] ListCollectionView.addItemAt Bug?



Well, it looks like either the documentation is wrong, or the code. The
ListCollectionView class has the following method defined:

    public function addItemAt(item:Object, index:int):void
    {
        if (index < 0 || !list || index > length)
            throw new
RangeError(StringUtil.substitute(resourceOutOfBounds, index));

        var listIndex:int = index;
        //if we're sorted addItemAt is meaningless, just add to the end
        if (localIndex && sort)
        {
            listIndex = list.length;
        }
        list.addItemAt(item, listIndex);
    }

Makes it very clear that the list isn't grown when the index exceeds the
length of the list. :-)

Anyone concur? If so, I'll submit a report to Adobe.

Jurgen

Jurgen Beck wrote: 

        It seems that there is a problem with the ListCollectionView
class when 
        using it with an ArrayCollection. Using the addItemAt method
produces an 
        index out of bounds error when an item is added with an index
that is 
        beyond the length of the collection.
        
        However, the Flex Reference states that:
        
        "If the list is shorter than the specified index, it will grow
to 
        accommodate the new item."
        
        Is this a confirmed bug, or am I overlooking something?
        
        Here is some test code to check it out:
        
        <?xml version="1.0" encoding="utf-8"?>
        <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> "
        creationComplete="initApp()"
        layout="vertical">
        
        <mx:Script>
        <![CDATA[
        import mx.collections.ArrayCollection;
        
        private var collection:ArrayCollection = new ArrayCollection();
        
        private function initApp():void {
        
        var newObject:Object = new Object();
        newObject.test1 = "test1";
        newObject.test2 = "test2";
        
        collection.addItem(newObject);
        
        newObject = new Object();
        newObject.test1 = "test3";
        newObject.test2 = "test4";
        
        collection.addItemAt(newObject, 3);
        
        }
        
        ]]>
        </mx:Script>
        
        </mx:Application>
        
        Anyone run into this too?
        
        Jurgen
        
        

 

Reply via email to