It’s not often you see updates to the ActionScript 3 class APIs these days, so I was pleasantly surprised to see that the AIR 19 beta introduces two new methods to the Vector and Array class:

  • insertAt()
  • removeAt()

They are intended as a replacement for the splice() method when you only want to add or remove a single element. So why use them over the splice() method? Well both methods make a change directly to the array or vector rather than creating and returning an altered version. They’ve been implemented with performance in mind and will perform better than the existing splice() methods.

To show the new APIs in action, here are two quick examples.

In the first example I add a score of 800 to the 2nd element of a vector of high scores:

var topScores :Vector.<int> = new <int>[1000, 500, 250, 100, 50];
topScores.insertAt(1, 800);
trace(topScores); // [1000, 800, 500, 250, 100, 50]

And in the second example I remove the lowest score from the array and trace it:

var topScores :Vector.<int> = new <int>[1000, 500, 250, 100, 50];
var lowest :int = topScores.removeAt(topScores.length - 1);
trace("The lowest score of " + lowest + " was removed.");

You can download the AIR 19 beta from Adobe Labs.