0
votes

I'm having a problem, whenever I try to remove an element from the array it gives this error #2025. The object is not visible on stage anymore when I click on it but it always gives this error.

//remove items  inventory 
    public function RemoveObject(mc:MovieClip)
    {
        var checkRemove:Number = curSlot - 1;
        trace("current slot " + (curSlot-1));
        trace("current pos array" + myIndex);

        for(var i:int = 0; i < itemS.length;i++)  {
            this.removeChild(itemS[checkRemove]);
        }


    }
2
do you want to remove one item ? - mgraph

2 Answers

0
votes

do not use for just :

this.removeChild(itemS[checkRemove]);
0
votes

If you wants to remove more than one items, Use for each loop because when ever you remove a child container would re-index other childs it contains.

for each (var child:DisplayObject in this.getChildren()) {
    this.removeChild(child);
}

and if you wants to remove only one item then it can be done as

this.removeChild(this.getChildAt(childIndex));

following methods of Container are also helpful to get desire child

getChildByName(name:String):DisplayObject
getChildIndex(child:DisplayObject):int

and its better to check first that child you are going to remove is in container or not

var child:DispalyObject = this.getChildAt(childIndex);

if(this.contains(child))
{
  this.removeChild(child);
}

Hopes that helps