Monday, February 21, 2011

Removing multiple object from array

I place the MC in an array and would like to remove it later on from an index maybe till the end.

//Removeing MC from stage, from an index till the end
LISTmc.removeChild(listArray[clickedIndex+1]);

//Removing MC starting from an index till the end
listArray.splice(clickedIndex+1);

Is the way to remove the MC from the stage same with removing it from array?

From stackoverflow
  • Do you mean that for the MovieClips in the array you remove you also want to remove those from the stage?

    for (var i:int = clickedIndex+1; i < listArray.length;i++)
    {
      //if this is on timeline leave as is otherwise you need to reference stage
      removeChild(listArray[i]);
    
      //if the movieclips are in various movieclips then you can do:
      // var parent:DisplayObject = (listArray[i]).parent;
      // parent.removeChild(listArray[i]);
    
    }
    
    listArray = listArray.slice(0,clickedIndex);//returns a new array from start index to end index
    

0 comments:

Post a Comment