Archive for February, 2010

Using binary data in Actionscript 3

Wednesday, February 24th, 2010

This is for anyone who’s having hair-tearing issues with working with binary data in Flash or Flex, or for those who want to be working with it.

(more…)

HaXe fun

Saturday, February 20th, 2010

Check out my first visual experiment with HaXe, an excellent new(ish) programming language that can compile to swf!

(more…)

addEventListener() is the new malloc()

Wednesday, February 10th, 2010

Remember back when you learned C? Way, way back in time? Well I do. When I recall my experience with C, I remember it being intoxicatingly fast and powerful. Kinda felt like mainlining into an artery of the machine: so much potential for incredible speed, but also horrendously dangerous and unforgiving.

(more…)

Strange Flash framerate issue

Wednesday, February 10th, 2010

I noticed today that the Flash game I’m working on has some odd framerate quirks, and I was wondering if anyone else has noticed similar behaviour. I know that Flash’s framerates can be quite unsteady at the best of times, but this is not the issue I’m having (at the moment).

I’m using Flash CS4, and the fps is set to 30. However, when I run it normally (within flash using “Test Movie”) I get a frame rate of 19.95 fps or so, and it’s quite steady. When I run it externally, with the flash player or in a browser, I get pretty much exactly 30 fps.

The frame rate in Flash remains at about 19.95 even if I bump up the fps to 60, even though this is faster fps is reflected correctly when it’s run externally. The game is a simple tile-based puzzle game, and is certainly not CPU bound. When running inside Flash, it’s using about 13% of the CPU.

When I set the framerate to, say, 10 fps, it runs at the correct speed everywhere.

Anyone have similar experiences with Flash? Any advice?

Saving time when dynamically constructing BitmapData subclasses created in Flash

Wednesday, February 10th, 2010

When constructing custom BitmapData subclasses which have been defined in the Flash Studio (such as MyFancyBitmapData), it turns out that you don’t actually need to pass the correct width and height of the bitmap. The MyFancyBitmapData class completely ignores its two (required) constructor parameters, and uses hard coded ones.

So don’t bother meticulously violating DRY principles when creating these things dynamically. You can pass any integers you like, including zero or negative one, but I particularly like using NaN because it makes it clear that you’re not even trying to supply a number that could possibly be interpreted in any meaningful way (even if that’s a tad passive aggressive…)

// e.g.
var myBitmapData:BitmapData = new MyFancyBitmap(NaN,NaN);
trace(myBitmapData.width + ", " + myBitmapData.height); // outputs: 45, 45

It seems a bit ugly to me that the generated BitmapData subclasses require their parameters. I really do think they should be optional at the very least, and ideally, illegal.

Hope this saves someone some time.