When constructing custom BitmapData subclasses which have been defined in the Flash Studio (such as MyFancyBitmapData), it turns out that you don’t actually need to pass the correct width and height of the bitmap. The MyFancyBitmapData class completely ignores its two (required) constructor parameters, and uses hard coded ones.
So don’t bother meticulously violating DRY principles when creating these things dynamically. You can pass any integers you like, including zero or negative one, but I particularly like using NaN because it makes it clear that you’re not even trying to supply a number that could possibly be interpreted in any meaningful way (even if that’s a tad passive aggressive…)
// e.g. var myBitmapData:BitmapData = new MyFancyBitmap(NaN,NaN); trace(myBitmapData.width + ", " + myBitmapData.height); // outputs: 45, 45
It seems a bit ugly to me that the generated BitmapData subclasses require their parameters. I really do think they should be optional at the very least, and ideally, illegal.
Hope this saves someone some time.
Tags: Flash and ActionScript, Rant