or Connect w/Facebook

Actionscript Caveats, Gotchas, & WTF – Part 1

September 16th, 2009 - filed under Programming

This is what I would like to do to the designers of Actionscript:

There are very few good large scale games written for Flash, and there’s a good reason why: Actionscript is chock full of undocumented problems that Adobe is either unaware of or unwilling to fix.  I feel bad for anyone who was introduced to programming with this language.  I wish I had documented all the roadblocks I’ve had to work around, but I’ve only got a small sample of the most heinous or recent ones that are causing headaches.  I don’t have any saved up for part 2 of this series, but I’m confident that won’t be a problem.

Mysterious Arrow & Numeric Key Issue

Recently, on one of my computers, arrow and number keys are firing key-up immediately after key-down, so you can’t tell if one of the keys is held down.  Many flash games never catch the key-down event at all, so most flash games are unplayable for me on this computer.  I have no idea why – I’ve tried several recent versions of the Flash player and both the debug/release versions, both in-browser and standalone.

Mysterious Faint Box

On another one of my computers, whenever an object is rotated a very faint solid rectangle appears behind it.

The Registration Point Problem

Most graphical objects in Actionscript have a registration point (or “center”) at the object’s center, meaning when you set an object’s position you are saying where the center of the object should be.  This also means that rotation occurs more or less as you would expect.  Bitmaps don’t work this way – the registration point is the top left of the object.  There is no way to move the registration point.  What you have to do – and all this is completely undocumented – is hack a solution by applying an offset via matrix transformation, and never again using the object’s x, y, or rotation properties.  There are many many people asking about this problem on the web, and only a few partial solutions are out there.  I wasted an entire day and pulled out a lot of hair figuring this out.

Alpha / ColorTransform is slow

If you change the opacity of your visuals, you’ll notice a significant drop in performance.  I was suprised by this, because I’m also importing graphics with an alpha channel, and those don’t have the slowdown.  I’m guessing that Flash’s drawing algorithm must be applying the alpha as a separate step before the blit, rather than doing it during the blit.  To get around this and other suboptimal behavior, I’ve written a system to automatically cache a graphic after all the effects are applied, and mark the cache dirty when an effect changes.  Also, when opacity is set to zero the processing continues unabated – you need to manually set the graphic’s visibility off when this happens.

More Reading

There used to be some other websites with more Actionscript issues, but they seem to be gone.  If you find any more, please share them.

Iconara’s Architectural Atrocities
Choice quote:

The ActionScript 3.0 API:s have a few interfaces, in general it’s a good thing, it shows that the Macromedia/Adobe developers actually understand something, which hasn’t been obvious in the past.
The decision to include interfaces in AS2 was probably a manager or marketing executive saying “hey, all the other languages have something called ‘interfaces’, why don’t we?”, and the developers quietly obeyed.

7 Responses to “Actionscript Caveats, Gotchas, & WTF – Part 1”

  1. Tim Kloske Says:

    I’ve never noticed anything like the two mysteries you’ve mentioned. Probably (hopefully) rare, hardware specific issues. MOUSE_WHEEL can be wonky too, so I’d stay away from that too as a primary aspect of gameplay… it’s especially wonky for (seemingly) random Mac users.

    The mysterious keyboard issue is probably some sort of driver issue.

    Two other possible hacks for your registration point problem are:
    - to use simple trig to offset the x and y to make it appear to rotate around a different center.
    - to nest a bitmap inside two MovieClips (or more likely sprites), and offsetting the x and y of the inner MovieClip. I’ve tested this method just now with MovieClips, and it definitely works. Not sure if this would impact performance, but it probably would knowing Flash.

    I’ve noticed the performance issue with alpha=0 as well.

    As long as the matrix transformation works, I’d probably stick with that. You might want to do a performance test and try all three of these methods though if you have the time.

    If I had the space I’d vent about more of my flash issues (like the lack of the ability to unload FLVs… I’ve looked and tried everything). Not that you would for this project, but don’t put a lot of static text in your fla. It doesn’t matter how much you spread the text out frame-wise, it will lag the entire IDE to a halt.

  2. Denilson Says:

    That rectangle box MIGHT be related to using “High color” (15 or 16-bit color depth) instead of “True color” (24 or 32-bit). I remember I had something similar to what you describe loooooong time ago, in Flash 5.

  3. Syniphas Says:

    Those are some of the reasons I never liked Flash.

    If you want my opinion, you shouldn’t be doing it as a browser game, but again as actual standalone game like Jetpack (perhaps even another DOS game, people still like those and play them with DOSBox, I know I do).

  4. Adam Says:

    Ahh the color depth might be the culprit, I’ll look into that.

    It will be standalone also, but making it a web game makes it more accessible.

  5. Syniphas Says:

    Yeah, I guessed so, but still my point is not that you make it just a standalone game, but a standalone game not made in Flash, and rather a decent programming language such as C.

    Also, I just realized that not only Squarez and Jetpack were made by Adept Software, but also God of Thunder! I recently found a shareware version in an old 1994 CD I had lying around for ages. I just downloaded the full version from the site, this game is epic!

  6. Nintendo Maniac 64 Says:

    There’s always other standard in-browser technologies such as those in HTML5 (canvas, svg, audio tags, etc) that would enable browser-based gameplay without using flash at all.

  7. Adam Says:

    @Nintendo Maniac 64: Now that’s a challenge I never want to take on! However there are some interesting games written for DHTML, especially Lemmings: http://www.javascriptgaming.com/search/label/DHTML?Tech&updated-max=2009-03-08T08%3A32%3A00-07%3A00&max-results=10

Leave a Reply

You must be a member to participate. Completing this form will create your account on JetpackHQ.


  • Categories