32K - Say It Ain't So!



One odd thing that I only ran into when I started working with ActionScript seriously is that classes in AS 2.0 can be no larger than 32K. This limitation makes AS development more complicated than it should be. I've seen some postings that suggest that this is due to limitation of the SWF file format. Apparently this was a problem even is the AS 1.0 days in MX when certain code sections couldn't be larger than 32K. In those cases, Flash wouldn't even flag the error-it just would give you unpredictable results.

Now, in MX 2004 you receive an error message from the Flash IDE - but here's the funny thing - you will only receive it the first time you compile your ActionScript. Everytime after that that you try it, the error message won't reappear (but you will still get the screwy results from the resultant SWF). You can close Flash down, relaunch it and the error message will reappear. This appears to be due to a bug in the way Flash caches compiler results.
The way to get around the limitation is to take some of your methods out of your class and move them into a superclass that your class inherits from. (This can be a little tricky if most of your methods are interdependant).
I haven't tried this in 8 as of yet.


3 comments :

Anonymous said...

There may be some special cases that I am not thinking of, but if your class is anywhere near that big, you should probably rethink your software architecture.

A class should do one thing, and do it well. You should use inheritance and composition to break out your functionality in a logical, object-oriented way.

Just my 2 cents.. :)

Anonymous said...

I agree. I hit the 32k limit on a project about 6 months ago.

To be honest, it was because I was being lazy (= deadlines too tight / get it done fast / feature creep) to split the code like I should have.

Anyway, after splitting the class into a base class and 3 inherited children, development proceeded much smoother as I didn't have to troll through those thousands of lines :)

I believe a rethink is definitely in order by the time you hit that limit...

And yes, F8 still has the limitation.

Anonymous said...

This is a pain for large data structures. The Flash compiler supports it, why can't mtasc?