0
  public var streamList:ArrayCollection=new ArrayCollection();
  //am getting the streamList dynamically like WebUser7,WebUser11.....      
  private function streamSynch(event:SyncEvent):void
    {
        if(streamList.length>0){
        //(streamList)here in streamList am getting the all values(old)
            streamList.removeAll();
        }
        var results:Object = event.target.data;
        for( var item:String in results ) {              
            streamArray.push(item);     
        }
        streams = new ArrayCollection(streamArray);
        streamList=streams; //(streamList)here in streamList am getting the all values(new) like Webuser9,WebUser2,WebUser11......
        From my Example i need to add the   Webuser9,WebUser2,WebUser11,WebUser7    
    }

古いものと新しいものを比較し、古いものを置き換えて新しいものを追加する必要があります...

4

1 に答える 1

1

ArrayCollectionメソッドを使用してこれを行うことができますsetItemAt(item:Object, index:int):Object。置き換える要素のインデックスを知っている必要があります。

編集:

使用例あり

function arrayCollectionExample () : void {

    // create instance of array collection
    var arrayCollection : ArrayCollection = new ArrayCollection();

    // create some object that we will add to collection
    var obj1 : Object = { name : "Object1" };
    var obj2 : Object = { name : "Object2" };
    var obj3 : Object = { name : "Object3" };

    // add those objects to collection
    arrayCollection.addItem( obj1 );
    arrayCollection.addItem( obj2 );
    arrayCollection.addItem( obj3 );

    // and now let's create a new object that we will want add instead of obj2
    var obj4 : Object = { name : "Object4" };

    // lets say that we don't remember that index of obj2 in a collection is "1". We have to get from collection
    var obj2Index : int = arrayCollection.getItemIndex( obj2 );

    trace( obj2Index ) // 1

    // now when we know index we can replace obj2 with obj4
    arrayCollection.setItemAt( obj4, obj2Index );

    // now when we have replaced values we can see that item at index "1" property "name" is "Object4"
    trace( arrayCollection.getItemAt( obj2Index )["name"] ) // "Object4"

}
于 2012-08-21T07:24:03.147 に答える