Archive for October, 2009

Function Performance

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 entry »

Tags: , , , , , , , , ,

47 Comments

Simple TextField Marquee

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 entry »

Tags:

13 Comments

Shape vs. Sprite

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 entry »

Tags: , , ,

14 Comments

Constructor Function

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 entry »

Tags: ,

7 Comments

Repeatable Random

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 entry »

Tags:

10 Comments

Building XML

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 entry »

Tags: ,

12 Comments

Try/Catch Slowdown: Part 2

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 entry »

Tags: , , , ,

2 Comments

Try/Catch Slowdown

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 entry »

Tags: , , , ,

7 Comments

Test Harness

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

Read the rest of this entry »

Tags: , ,

No Comments

Reverse Currying

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

Read the rest of this entry »

Tags: , ,

2 Comments