Archive for the 'ActionScript' Category

parseInt and hexatridecimals

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 issue seems to be fixed in ActionScript 3.

Quoted in “Professional Cairngorm”

Seems like I’ve been quoted in a book with the (contradictory) title Professional Cairngorm. It’s the now (in)famous Architectural Atrocities 9: Cairngorm’s Model Locator Pattern again. It’s not the best quote to take from that post, but beggars can’t be choosers.

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.

Debug both Flex and AIR apps from the same FlexBuilder project

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.

Read the rest of this entry →

Architectural Atrocities, part 11: Not yet another namespace construct

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.

From Gumbo Component Architecture

So what are they going to do for Flex 5, use “Fx2″?

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.

I remember when AIR was called Apollo and the WindowedApplication class was called ApolloApplication. This is the same kind of short-sightedness.

* 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).

Update: Adobe has decided to revert the decision of prefixing the new Gumbo classes. Good for everyone.

How to work around the lack of ExternalInterface.objectID in ActionScript 2

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.

Read the rest of this entry →

A very localized bug indeed

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.

Read the rest of this entry →

Ichabod explained

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.

Read the rest of this entry →

Architectural Atrocities, part 10: Cairngorm’s Service Locator

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.

Read the rest of this entry →

Creating a document-based application with Mate

Over the last few weeks I’ve put together an example application that shows how to build document-based applications with Mate. I’ve also started a Google Code project for Mate examples and extensions, and if you’re interested to contribute please contact me.

Talking Flex SEO on The Flex Show

Jeff and John were kind enough to have me on the Flex Show to talk about Flex and SEO. If you follow this blog you’ve read it all already, but it never hurts to hear it again.