Guys, I am thoroughly surprised that there is no Flash Hidden Features post yet in the Hidden Features series that I've been tracking for a while now.
There is a recent AS3/Flex one but it's not very active and I don't exactly mean just AS3 when I say Flash here.
The Hidden Features series is great for people who are new to a certain language. It shows the ropes and certain valuable tricks, all in one place. I think it's a brilliant idea. Even experts sometimes find tricks they'd never heard about.
When I started with Flash, I was taken aback by the Flash IDE and odd concepts of Flash, compared to other programming languages.
So, here goes: what are some hidden features of Flash as a language (AS2/3) and the Flash IDE?
Let the fun begin.
[AS3] Tips for working with arrays or Vectors
Fastest way through an array, always from the back
var i:int = array.length;
var item:Object;
while(i--)
{
item = array[i];
}
Clearing an array,
//faster than array = []
array.length = 0;
//garbage friendly
while(array.length)
{
array.pop();
}
Pushing and splicing
//faster than array.push();
array[array.length] = "pushed value";
//faster than splice(index, 1)
var index:int = array.indexOf(splicee);
array[index] = null;
array.splice(array.length, 1);
Cloning
//fastest way to clone
var newArray:Array = array.concat();
//fastest manipulation
var mapFunction:Function = function(item:Object, index:int, source:Array):Object
{
return //your cloning or morphing here
}
var newArray:Array = array.map(mapFunction);