The ByteArray
class, introduced in Flash Player 9, has a pair of very powerful functions alongside all the usual ones like writeInt
. It actually allows you to read and write AS3 objects and provides an easy, fast, and compact way to serialize anything without writing any code. Today’s article explores shows you how to harness the power of these functions to improve your data serialization and deserialization.
Posts Tagged class
I recently received a tip about a thread discussing an interesting problem: how to tell if one Class
object represents a class that subclasses another Class
object. If you had an instance of the class, you could simply use the is
or instanceof
keywords, but that won’t do here. Today’s article shows how to solve this tricky problem.
One of the very nice features of AS3 (and AS2 and JavaScript for that matter) is that you can dynamically access the fields of any object. This leads to much more dynamic code since you no longer need to know what field to access at compile time. As we’ve often seen with other dynamic features, this can come at a steep cost in terms of performance. Today we’ll see just how slow accessing fields this way is to get a good idea of just how much performance we give up when using this feature.
AS3 has an interesting feature that is sometimes used to great effect: dynamic classes. These classes can have fields added and removed to them and used like any other field. You can even make your own dynamic classes with the dynamic
keyword. However, all of this fancy functionality comes at a steep performance cost. How steep? Read on to see just how steep.
Today’s article follows up on an article I wrote way back in August of 2009 about the order of operations when you use a class. In the original article I showed the order of field initializers and constructors. Today I’m expanding on that to show three more chunks of code that are run. Can you guess what those chunks are?
One of AS3’s strong suits is its ability to very easily use classes in a dynamic way. Every once in a while, this leads MXMLC to completely remove some of your classes from the output SWF and you then get some very strange behavior. Read on for some strategies for using dynamic classes without going insane.
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)
I was reminded about the flash.sampler API by Grant Skinner’s recent post about it. While only available in the debug player, it can still tell us some valuable information about what goes on in the release player. Today I’m using the getSize function to find out how much memory overhead various classes impose, even when they are empty.
The last three articles have been about utility functions for objects, classes, and display objects. This is the finale in the series and contains some leftover utility functions.
On the heels of last Friday’s article on Utility Functions For Objects, today’s article will show a few utility functions for the Class class. In case you’re not familiar with it, Class represents a class like you would write and is useful main for more dynamic programming where you want to instantiate a class based on a variable (eg. var c:Class) rather than a constant (eg. BitmapData). So how do you get a Class variable? The Flash API provides some ways to go about it and I’ll provide some ways to make that more convenient.