Wednesday, September 19, 2007


I've heard lots of folks complain about how using any ActionScript classes from Adobe causes extreme bloat. A lot of this is Flex framework related, and Adobe is hard at work at solving this problem by caching the framework on the Flash player. But sometimes it's even more subtle.

I was writing a library class today. I ran across two common problems. First, I needed to do some value based comparison. There should really be an equals method in ActionScript to make this trivial, but whatever. I came across this blog stating that you need to use the mx.utils.ObjectUtil class to do value based comparison. This is still not as good as having an equals method to override, because it's all or nothing, but it was good enough.

Next, I needed to do some rounding on a floating point number to a given precision. Once again there is something in ActionScript in the mx.formatters.NumberBase class. It has a formatRoundWithPrecision function that was exactly what was needed. It was a little awkward, since it takes in a String not a Number, but again whatever.

Using these two library classes caused my library to triple in size! The SWC went from 11kb to 38kb. I had added some other code, too, but it wasn't that much. So I stripped out these two function calls, implemented them myself. Now my SWC was back down to 13kb.

I knew using the Flex framework was expensive, but this was not the Flex framework. This was just a couple of utility classes.

No comments: