In my last article on getProperties, there was one strange finding in the tests of standard classes: the Function
class seems to have a length
field. What is it? Today we’ll see
Archive for category AS3
Quite often I have wanted to iterate over the public fields (and getters) of an arbitrary object. Sometimes this is for debugging purposes so I can print out the state of an object, particularly one that has all public fields like a C/C++ structure. Sadly, this is not possibly (with most objects) using the for-in
and for-each
loops we’ve come to know and love. So I made a utility function that I’m sharing with you all today. UPDATE: getProperties now supports MovieClip
derivatives such as library symbols from an FLA
Continuing from last week’s article on recursion limits, today we’ll talk about recursion speed. Is there a penalty for making recursive calls? Does it increase as the recursion gets deeper and deeper? Read on to find out.
Recursion is a commonly-used feature of many programming languages, including AS3. It’s useful for everything from trivial examples like computing the Fibonacci sequence all the way up to advanced sorting techniques like Quicksort and tree algorithms. This article is a first in a series all about recursion. Today we’ll see what kinds of limits the Flash Player puts on us as recursion-using AS3 developers.
I’ve talked before about explicit type conversion and used the function-call style (Type(obj)
) and the as
keyword to accomplish the task. Today, I’m going to talk about implicit type conversion and use—as implicit would imply—no operators at all!
There are actually three ways to call a function in AS3. Can you name all three? Do you know which is fastest? Does the type of function being called matter? Today I’ll tackle these questions and find some surprising facts about the three ways to call a function in AS3.
Amazingly, I’ve never covered the const
keyword, but a couple of recent comments have prompted me to cover the subject in depth with today’s article.
I recently received an e-mail from asking which is faster: a DisplayObjectContainer
or a Vector
of DisplayObject
. To ask this is to question whether or not we can do better than the Flash Player’s native container of DisplayObjects
using AS3. It turns out that we can. Read on for several ways to improve on DisplayObjectContainer
‘s speed.
There are three main ways to access the contents of objects in AS3: the dot (.
) operator, the index ([]
) operator, and the in
operator. The first two are well known and functionally-equivalent because obj.property
evaluates to the same value as obj["property"]
. The in
operator is different as I’ve described before: it returns a Boolean
indicating whether or not the object has the given property. There are a lot of cases—error checking, for example—where we only care if an object has a property and not what that property is. So, can we improve performance by using the is
operator rather than the index or dot operators? (UPDATE: hasOwnProperty results added)
Closures are a really nice feature of AS3 (and JavaScript and AS2) and I’ve shown their performance disadvantages compared to regular methods before. Today I’ll discuss a further performance downside to closures that can slow down your code, not just the function call itself.