There are many ways to clear an Array or Vector. I’m tired of seeing the foolish ones. Read this and make sure you’re not doing anything foolish:

Here’s one way to clear an Array or Vector that’s both wordy and slow:

vec.splice(0, vec.length);

Not only do you have to take the length of the vector and then go into a general-purpose slicing routine hoping that it optimizes the slice for you, but you had to type a lot. Here’s an even dumber way:

vec = vec.filter(
	function(cur:Point, index:int, vec:Vector.<Point>): Boolean
	{
		return false;
	}
);

Yes, it uses functional programming. It’s horribly slow though. It’ll result in n calls to your AS3 function for a n-length vector. It’s also a ton to type. Unless your functional-style programming has made it really convenient for you to use that approach and really tough to use any other, don’t do it! Here’s a much more sane way that actually has a couple advantages:

vec = new Vector.<Point>();

The advantages here are that this won’t crash if vec is null and you get an entirely new vector. As such, it’s a good initializer, but not much else. It’s still more typing than the best way to do it. Here it is:

vec.length = 0;

Tada! This is the one with the least typing, the fastest speed, and the only one not doing another allocation and unreferencing an object. The downsides are that it will crash if vec is null and it won’t get you a new object if you need one. So there you have it. That is the clear winner as far as clearing a vector or array goes. This will also work in JavaScript, just not on Vectors of course.