Posts Tagged ‘Rant’

onReleaseOutside for AS3

Wednesday, March 24th, 2010

Recently I was horrified to learn that there is no AS3 equivalent for the AS2 event “onReleaseOutside”. I consider to be an extremely useful and important event. Although it can be emulated faithfully with the provided mouse events and a complicated bunch of calls to add/removeEventListener, it’s something you have to implement again and again. Because I was too lazy, I’ve been grumbling, sighing, and copy-pasting code without much more thought.

But as it turns out, I don’t have to anymore because Tyler of xtyler.com has released a super-groovy as3 library for making any InteractiveObject behave as a button.

Siic! [sic]

Saving time when dynamically constructing BitmapData subclasses created in Flash

Wednesday, February 10th, 2010

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.