Archive for category AS3

Constructor Function

Tags: ,

It’s very nice in AS3 to simply state the name of a function and get a Function variable back, regardless of whether or not it is a method, static method, dynamic function, or plain function in a package. Most other languages do not allow this level of convenience. Java doesn’t allow it at all and C++ and AS2 require fanciness in order to pass the this pointer. However, when you want a Function for the constructor of a class, you get a Class variable back. This article will show you a way to get a Function variable that will create an instance of a class when called.

Read the rest of this article »

8 Comments

Repeatable Random

Tags:

Everybody knows about Math.random(), and for good reason. It’s pretty much the way to get random numbers in AS3, AS2, and JavaScript other than bizarre alternatives like AS3’s BitmapData.noise(). However, it has one critical problem that arises when you want to repeat a certain test or prevent game cheaters from exploiting the randomizer until they get an “easy” setup or desirable outcome. This problem is the lack of repeatability.

Read the rest of this article »

10 Comments

Building XML

Tags: ,

The Flash API provides a very nice set of XML classes along with syntax sugar in its E4X implementation. You can use this to not only read XML that you download, but also to write out XML that you upload. Unfortunately, it turns out that this is horrifyingly slow. Today we’ll do a little experiment to exemplify this.

Read the rest of this article »

12 Comments

Try/Catch Slowdown: Part 2

Tags: , , , ,

Today’s article is in response to a comment left about my article on try/catch slowdowns. The second time around I will provide an example that is hopefully more “real world” than the last article provided.

Read the rest of this article »

2 Comments

Try/Catch Slowdown

Tags: , , , ,

Try/catch blocks are certainly a nice feature to have. They allow you to catch errors that are beyond your control and handle them in a nice manner. They also allow you to throw your own errors and handle them in the same way. This would all be great if it weren’t for the fact that they are tremendously slow. Read on for some surprising test results.

Read the rest of this article »

7 Comments

Test Harness

Tags: ,

There are other test harnesses out there, but today I thought I’d share one of my own.

Read the rest of this article »

No Comments

Reverse Currying

Tags: ,

As a followup to last week’s article on curry functions, today’s is about the reverse of currying.

Read the rest of this article »

2 Comments

Loop Speed

Tags: , , , , , ,

AS3 gives you a good number of potential ways you can loop over collections. When Flash Player 10 first came out, I went ahead and tested out the new Vector class in a variety of ways. One of them was to pit it against the collections available in Flash Player 9: Array, Object, Dictionary, ByteArray, and even BitmapData. Below I’ll show you my test and discuss its results.

Read the rest of this article »

14 Comments

Inline Math.ceil()

Tags: , ,

Math.ceil() is a common, mundane function that you likely call all the time. I know I do. If performance gets to be important and you have a Math.ceil() in some inner loop or frequently called function, consider inlining it. Below I’ll show you how and provide a test app showing you just how much CPU time you’ll save.

Read the rest of this article »

11 Comments

RegExp In An Anonymous Function

Tags: ,

Regular expressions are downright handy for a variety of string processing tasks. They are so handy that they are built straight in to the language in the form of the /regexpgoeshere/ syntax. Well, usually…

Read the rest of this article »

6 Comments