Introduction
Over the last few weeks I have been learning ActionScript on the job. I come from a C# and C++ background and would like to share a few tips for programmers experimenting with ActionScript 3. This is by no means a complete resource on the subject and I will correct this article based on feedback in the comments.
Types
ActionScript 3 has 32 bit integers but no 64 bit integers, signed or unsigned. The Number class is a IEEE-754 double-precision floating-point number, so does not cover the same range as a 64 bit integer (53 bits vs 64 bits). There are also warnings about performance in Adobe Number documentation.
Arrays are “Adobe Array documentation for more details.
Vectors are “dense arrays” where each element has a value. All elements are expected to be the same data type. Vectors seem closer to what programmers from other languages may think of as an array. The Adobe Vector documentation lists pros and cons of using vectors over arrays, one of which is performance.
Without the RegExp class) only matches the first item.
Operator == vs ===
There are a few more operators to look out for in ActionScript – a few existing ones have their meaning changed too. [Adobe Operators Documentation]
Lets start off with ‘strict equality’ (==).
The == operator attempts to convert things to a common form for comparison and in the case of objects, arrays and functions falls back to being compared by reference. In short a string with the value “1″ will match a numeric type with the value 1 through an implicit conversion.
The === operator still tries to convert between different numeric based types (Boolean, int, Number and uint) but not for anything else. Variables representing anything else are compared by reference.
Operator >> vs >>>
There are two types of shifting types to think about and in C++ the shift is context sensitive on the type. The logical shift moves all bits in the operand. In C++ this is what an >> operation does on an unsigned type; in ActionScript to do the same operation use the >>> operator.
The alternative type of shift is an arithmetic shift which happens in C++ on signed types. Both C++ and ActionScript use the >> operation.
0111 1111 1111 1111 1111 1111 1111 1111 = 2147483657 = max value of 32 bit signed int
1111 1111 1111 1111 1111 1111 1111 1000 = -8 int or uint 4294967288
0111 1111 1111 1111 1111 1111 1111 1100 = 2147483644
1111 1111 1111 1111 1111 1111 1111 1100 = -4 int or uint 4294967292
1111 1111 1111 1111 1111 1111 1111 1110 = -2 int or uint 4294967294
1111 1111 1111 1111 1111 1111 1111 1111 = -1 int or uint 4294967295 = max value of 32 bit unsigned int
So the bit patterns between -8 >> 1 and -8 >>> 1
1111 1111 1111 1111 1111 1111 1111 1000 = -8 Input
1111 1111 1111 1111 1111 1111 1111 1100 = -4 Output ActionScript >>
0111 1111 1111 1111 1111 1111 1111 1100 = 2147483644 Output ActionScript >>> or unchecked C# >>
Note how >> keeps a 1 on the first bit, where >>> puts a zero in the left most bit.
For further information, see the code examples in Adobe documentation.
Conclusion
This article is ripe for expansion. Please link to other resources in the clients, and if any other authors want to discuss this, go ahead!
EDIT: Please read the comments, people have already been contributing good tips. :0)