Search code examples
arraysactionscript-3array-splice

Removing a specific element from an array by name in AS3


I would like to remove a specific element from an array, not by index because the index value of that item is not static.

myarray.splice(myclip, 1);

When I use this code instead flash removes the first element in the array. Is there something I am missing here?


Solution

  • Documentation of splice()

    Both parameters need to be integers, the first one is the position of the element you want to delete, and the second one is the amount of elements you want to delete. Try myarray.splice(myarray.indexOf(myclip),1);

    Don't know why it would only remove the first element in your snippet, maybe internally it casts myclip to 0? Doesn't matter, use indexOf. If that doesn't work, for loop through the array to get the position first.