Archive for category AS3

LocalConnection Speed

Tags:

For a variety of reasons, you may need to communicate between two Flash Player instances. You may do this to implement debug logging, communicate with a mini game, or coordinate between a main SWF and an advertisement SWF. So, what kind of speed can you expect? This article will show you.

Read the rest of this article »

4 Comments

Inlining Math Functions

Tags: , , , ,

As a followup to my article on Inlining Math.ceil(), I decided to inline some more functions in the Math class. Read on for the code as well as tests proving correctness and speed.

Read the rest of this article »

3 Comments

Faster isNaN()

Tags: ,

You cannot directly check if a value is NaN by comparing with it. AS3, AS2, and JavaScript therefore provide a useful isNaN() function to do this very check. However, it is very slow. Today I’ll show you a workaround that results in a faster isNaN(): (UPDATE: see the definitive article on isNaN for much more!)

Read the rest of this article »

22 Comments

Var Args Is Slow

Tags: ,

Var args (a.k.a. …rest) is a useful feature introduced in AS3. Previously in AS2 (and JavaScript still), we were forced to pass an Array of arguments where an unlimited-length argument list would have been much natural. Unfortunately, this can be really slow. In this article I’ll show a much quicker way to pass unlimited arguments to functions.

Read the rest of this article »

2 Comments

Beware of Getters and Setters

Tags: , , ,

Getters and setters are indeed a very nice feature of AS3. They eliminate a lot of typing (.x versus .getX()) shaves off five characters and removes the need to hit the shift key for X) and make getting and setting values much more natural by disguising the fact that you’re actually calling a function. The downsides include the difficulty (impossibility?) of getting a Function variable for them and lower performance. This article is about that performance hit. EDIT: added a plain getter test)

Read the rest of this article »

13 Comments

Simple Regular Expressions

Tags: , ,

Lately I’ve been seeing a lot of AS3 code that uses regular expressions where the normal methods of the String class would seem to suffice. It seems common among programmers of all languages to catch on to new trends even when they do not particularly apply to the task at hand. For example, a new C++ or Java programmer may use templates or generics even for classes where only one data type will likely ever be used. I don’t know why programmers do this and I won’t attempt to tackle such a topic. Instead, I’ll do a test to show why this is a bad idea from a performance perspective.

Read the rest of this article »

2 Comments

Flexible If Syntax

Tags: , , ,

This article is sort of a follow-up to my article on Flexible Loop Syntax. This was reported to my by a coworker who spotted the anomaly. I guess he had done with if the same sort of thing that I had done with for. Read on for a little insight into how the comma operator interacts with the if statement.

Read the rest of this article »

5 Comments

Function Performance

Tags: , , , , ,

With access specifiers, statics, plain functions, and overriding, there are a lot of ways you can dress up a function in AS3. But how many programmers really know the performance implications of these options? Read on to find a straightforward test showing just that. EDIT: added functions defined in interfaces, getters, setters, and final functions.

Read the rest of this article »

48 Comments

Simple TextField Marquee

Tags:

A coworker recently needed to marquee some text in a TextField. Having searched for this on the internet and found nothing for AS3, I decided to implement it. Turns out it’s really simple. The code is below.

Read the rest of this article »

13 Comments

Shape vs. Sprite

Tags: , ,

Flash 9 and AS3 provide a lot of nice structure that Flash 8 and AS2 lacked. Instead of just MovieClip and TextField, we have a whole hierarchy of DisplayObject derivatives, including MovieClip and TextField. Most AS3 programmers know that Sprite is a more efficient class than MovieClip and have grown to use them when animation is not required. However, I find that very few AS3 programmers ever use some of the other, more obscure DisplayObject derivatives. Today I’ll talk a little about one of them: Shape.

Read the rest of this article »

19 Comments