Another find and replace prototype that might be useful for someone. Flash has some useful inbuilt functions like pop() which make life easier, but this prototype will search an array for a particular value and remove it, returning the new array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Array.prototype.removeArrayItem = function (item)
{
	i = 0;
	while (i < this.length)
	{
		if (this[i] == item)
		{
			var pre = this.slice (0, i);
			var post = this.slice (i + 1, this.length + 1);
			return (pre.concat (post));
		}
		i++;
	}
};
 
var myArray:Array = ["one", "two", "three", "four"];
 
trace (myArray.removeArrayItem ("two"));

Alternatively, if you want to remove an item by its position in the array, rather that it’s value, just use this modified version:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Array.prototype.removeArrayItem = function (num)
{
	i = 0;
	while (i < this.length)
	{
		if (i == num)
		{
			var pre = this.slice (0, i);
			var post = this.slice (i + 1, this.length + 1);
			return (pre.concat (post));
		}
		i++;
	}
};
 
var myArray:Array = ["one", "two", "three", "four"];
 
trace (myArray.removeArrayItem (2));

Of course, remember that the first item in an array has an index of 0, not 1. If your brain is defective and you tend to forget that, just change the condition to i == (num+1)