Mastering C# and Unity3D

Archive for August, 2009

Adding on to existing arrays and vectors is one of those really common tasks that sounds dreary. Everyone knows about push() and unshift() for single elements and concat() for lots of elements. But what if you want to add a lot of elements to an existing array or vector without allocating a new array or vector? I have the solution.

While plainly documented by Adobe in the Flash 10 AS3 Docs, it seems as though few programmers know about the with statement. I don’t use them much personally, but when a coworker came across one in my code recently and was puzzled, I figured I would write a quick article to cover their usage.

Welcome to the second part of this series on dynamic access. Last time we covered indexing arrays and vectors. This time we’ll talk about dynamic classes and plain objects. These are definitely something to watch out for when writing performance-critical code.

The chief quality of Vectors is that they hold a single type of object. This is why they are sometimes called “typed arrays”. So what would happen if you wanted to convert an array of mixed-type objects into a vector?

Being allowed to declare and define member variables all at once introduces a question: in which order does the class boot up? Further, if the class has parent classes, how does this change things? Read on for the simple results.

AS3, AS2, and JavaScript have some strange rules regarding the initialization of variables. These are shocking and perhaps ridiculous to users of C and Java. This article covers one particularly insane quirk.

AS3 makes some strange things possible. Even stranger, it seems to do this without any warning by its compiler: MXMLC. It seems as though one of these strange things is the ability to override the variables of your parent classes.

Many classes in AS3 are dynamic, meaning that you can add and remove their fields at runtime. This is powerful, but extraordinarily slow. This series will cover some common ways you might be inadvertently using dynamic access or using it too much. This will help you make your code faster. In the first installation of the series, I’m going to talk about the simple act of indexing an array or vector.

The comparison operators (< , <=, ==, >=, >) are clearly core to any programming language. The AS3 docs tell us a little about AS3’s special handling of strings when compared, but there is more to the story.