Friday, July 3rd, 2009
AS3’s Dictionary Class. What?

UPDATE: As expected, I discovered some flaws in my previous implementation (since replaced!). While it's true that the class did in fact preload everything thrown at it, it didn't provide a way to actually do anything with it once it was loaded!

It's not exactly the most user-friendly implementation, but it's fairly straightforward, and I actually tossed a handful of comments throughout the code!

Until last night, I don't think I'd ever heard of the Dictionary Class in AS3. I certainly had no idea what it did.

That was before I was trying to create a multiple-asset preloader; something that would allow you to queue multiple assets (say, seven or eight JPGs, or 47 SWFs, or whatever) and show only one progress bar that tracked the entirety of bytes coming down the pipe. Initially, I thought I could keep track of a Loader object's loader property to keep track of which object's bytesTotal property had been added to a central aggregator of all loaded assets's bytes. I quickly learned that in Flash Player 9 and below, the loader property doesn't get updated until the entire loader has been loaded. Useful! (Not really.)

That's when my vast travels across the internet revealed one of AS3's darkest secrets: the Dictionary Class.

But wait! There’s more! »

_root._url isn’t as dead as I thought!

I'm probably the last person to figure this out, but just in case I'm just second-to-last, here's something I just figured out: In AS2, you could use _root._url to figure out the name of your SWF. In many of the projects on which I work, such functionality was precious! I was sad to lose it with AS3...until today!

That's right! While updating a class for use in AS3 projects, I needed an alternative to _root._url. A quick visit to Flash's help files (I know!) revealed the following:

myDisplayObject.loaderInfo.url

How is it that I've never seen nor heard about that until just now?! Ack!

Well, there it is! Now all of us know how to get the filename of our SWF!

Pumpkin stuff

Tonight, my wife (and our neighbors) carved a few jack o'lanterns (however it's punctuated). After searching in vain for almost forever (read: seven or eight minutes) for a totally sweet dragon head or something, I decided I'd tackle vintage, old school 8-bit NES sprites.

What a kick in the pants that turned out to be. I was originally going to attempt Warmech from Final Fantasy I. But he had too many colors (4, I think) and too many pixels. My second choice was Mario from Super Mario Brothers 3. That jerk has eyes in the middle of his face! (Because of the nature of carving with negative space, anything "white" gets tossed; anything gray or black remains.

This was our first time toying with varying levels of opacity: in hindsight, I should have scraped more material from the inside of the pumpkin before hacking and slashing; that said, however, I think the result is a moderate success!

Gooma o'lantern