Running AS2 Content in AS3: Beware!

It is perfectly possible to run an AS2 movie within an AS3 Flash application.

However, my advice would be - don't.

Here are a handful of the problems we've encountered when running any AS2 movie of any complexity within AS3:

  • If the contained AS2 movie (call it A) loads another AS2 movie (call it B), then for inexplicable reasons the built-in Flash API calls MovieClip.getBounds() and MovieClip.getRect() may start to return undefined. This can be partially fixed by setting _lockroot=true on the movie A, but may then start failing again the second time you load movie B. There seems no real rhyme or reason to this: we've only managed to get a consistently working getBounds() by repeatedly destroying and recreating a parent container to B's container.
  • (in our setup) If the contained AS2 movie makes repeated calls to BitmapData.draw(), even if all bitmaps are properly disposed, the contained movie eventually crashes the Flash Player.
  • There seems to be no obvious way to get the AS2 movie to accept keyboard input. We've got around that in our situation by trapping the keys in AS3 and forwarding them (via Grant Skinner's SWFBridge) - then faking calls to the listeners on AS2's Key._listeners array. (Oddly, if you call Key.getCode() at that point, it contains the correct code.)
  • hitTest(x,y) doesn't take account of any scaling of the parent movie i.e. the top-level AS2 root. The top-level AS2 doesn't know that it's scaled. So somehow you have to communicate the scaling from AS3 to AS2 and then multiply every point passed to hitTest() by that scaling.