Archive for the 'ActionScript' Category

There’s a bug in ActionScript 2′s parseInt: it strips “0x” or “0X” from the start of the string, regardless of the base. It’s ok in most situations, since “0x” isn’t a valid part of any number base — except 35 and 36. And that’s where the bug lies. If you run parseInt("0XABC", 36) you should get 1553016, but instead you get 13368, which is ABC in base 36.

There’s a very simple workaround (if anyone besides me is actually doing this and using ActionScript 2), and that’s to add “00″ to the start of any base 35 or 36 number passed to parseInt. Why not “0″? you may ask. That would only shift the problem to numbers starting with “X”.

The quote is on page 267 in the chapter “Criticisms of Cairngorm” (where else), and it can be found through Google Booksearch. The chapter also quotes Neil Webb as a critic of the Singleton pattern.

I applaud the author’s good taste in including a chapter on criticisms — although I think that if he really had taken the time to understand what both Neil and I have said he wouldn’t just put us under the sub header “Singled out — Bad Singleton, Bad”. Our critique goes far beyond Singletons and Monostates. Even so, if that is the level you aim for, then those things need to be said too.

For some reason FlexBuilder forces you to choose between creating Flex projects and AIR projects, and it doesn’t let you change a projects nature after it’s been created. This means that if you create a Flex project you will not be able to compile, debug or profile any AIR applications that you happen to build from the same code base. This has annoyed me to no end, but I have finally found the solution.

Gumbo introduces many new classes, some of which are re-implementations of existing Halo classes (and thus have the same name). In order to disambiguate between Halo and Gumbo, Gumbo classes are prefixed to avoid collisions. Gumbo components that have Halo equivalents, like Button, List and CheckBox, are now prefixed with the letters “Fx”. This means in MXML, a Gumbo Button would be instantiated via the <FXButton /> MXML tag, and a Halo Button would continue to be instantiated via the <Button /> MXML tag. Additionally, the new animation classes in Gumbo also follow the same prefix policy. A Gumbo resize effect is instantiated via the <FxResize /> MXML tag while a Halo resize effect is instantiated via the <Resize /> tag.

Seriously, ActionScript has three* namespace constructs already, why introduce a fourth? Using prefixes is a hack to get namespaces in language that lacks them (like C or PHP), but packages were invented to solve exactly this problem.

In MXML it’s dead simple to use namespaces and prefixes to differentiate between different components with the same class name (e.g. <mx:Button> vs. <fx:Button>). The only place where it gets a bit messy is in ActionScript, but it seems to me that it is a fringe case when you want to juggle both a Halo and a Gumbo button or both a Halo and a Gumbo list in the same class (a Halo list and a Gumbo button, sure, but that wouldn’t cause a clash). I can see it happening, but not often enough to warrant such an ugly solution as this.

* Three namespace constructs: packages, namespaces and XML namespaces (which are different from packages since you can manually flatten a package structure with a manifest, e.g. the Flex namespace contains both classes from mx.core and mx.controls, and others).

I would guess that not very many of those who read this blog have used ActionScript 2 lately. I have had the unfortunate luck of having to write some of it during the past few weeks and I don’t recommend it. However, I ran into a problem that I’d like to share the solution to, if anyone else would even find themselves in my position.

I found the nastiest bug the other day. I’m working on a small piece of code that will live inside ads made with Flash and reports some stats like the size and position on the page. I discovered that under some very localized conditions my code would make Safari crash. Hard.

The Adobe MAX sessions are online, and among them is a presentation by Jim Corbett about how Adobe and Google’s new Flash indexer works. I think it’s great to get such a thorough explanation from Adobe, but it’s a shame that they didn’t do this at the same time their PR people were busy hyping it a few months ago. Since it’s release it’s become obvious that it’s very limited, and there’s still no evidence that it works any better than the old swf2html method. Jim’s presentation makes it clear why this is — and I maintain my previous assessment that we’re better off using progressive enhancement/graceful degradation until there’s significant changes in the Flash Player to overcome the problems.

In this installment of the Architectural Atrocities series I’ll continue on the Cairngorm theme. This time it’s something that is truly an architectural atrocity if there ever was one, and one of the ugliest things I’ve seen in such a high profile piece of software that Cairngorm is (a fact that still baffles me): Cairngorm’s Service Locator.