Sponsored By

ActionScript Tips For Programmers Of C#/C++

In this reprinted <a href="http://altdevblogaday.com/">#altdevblogaday</a>-opinion piece, Portalarium's senior programmer Paul Evans offers some tips for getting a handle on ActionScript 3 from a C#/C++ programmer's perspective.

paul evans, Blogger

November 16, 2011

4 Min Read

[In this reprinted #altdevblogaday-opinion piece, Portalarium's senior programmer Paul Evans offers some tips for getting a handle on ActionScript 3 from a C#/C++ programmer's perspective.] 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 "sparse arrays" which are not necessarily a block of consecutive memory. An ActionScript array seems to be more like a table, where each position has a "next" redirection for the following defined value. There can be holes in the indexes that are undefined. The documentation warns against using a class to create associative arrays and suggests using the Object class instead. See 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 /g global flag regular expressions (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' (===) versus '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! [This piece was reprinted from #AltDevBlogADay, a shared blog initiative started by @mike_acton devoted to giving game developers of all disciplines a place to motivate each other to write regularly about their personal game development passions.]

Read more about:

2011

About the Author(s)

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like