I used this line of code to remove an element:
tiles.splice(tiles.indexOf(tiles[i]), 1);
Yet afterwards when I'm checking the value, it's still not null, in fact, it still contains the movieclip it had inside of it.
This worked though:
tiles[tr] = null;
The question is, is it still okay to do it like that? I have movieclips added and removed to this array and I type removeChild(tiles[tr); before removing it from the array.
I just don't want to encounter some terrible performance in the future,
Thanks.
tiles.splice(i, 1)
will work, no need to useindexOf
, see if this resolves the issue. Also are you wanting to have the contents of the element (a movieclip for example) tagged for garbage collection or just to have it removed from the array? – Simon McArdlesplice(..)
removes the element then shifts the remaining elements up one position, so if you splice the 2nd element in the array, the 3rd element will move up to take the position of the 2nd, the 4th will move to the 3rd position etc. This is maybe why your trace is still saying there is something at that position in the array. – Simon McArdle