Posts Tagged ‘Flash and ActionScript’

onReleaseOutside for AS3

Wednesday, March 24th, 2010

Recently I was horrified to learn that there is no AS3 equivalent for the AS2 event “onReleaseOutside”. I consider to be an extremely useful and important event. Although it can be emulated faithfully with the provided mouse events and a complicated bunch of calls to add/removeEventListener, it’s something you have to implement again and again. Because I was too lazy, I’ve been grumbling, sighing, and copy-pasting code without much more thought.

But as it turns out, I don’t have to anymore because Tyler of xtyler.com has released a super-groovy as3 library for making any InteractiveObject behave as a button.

Siic! [sic]

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.

Catmull-Rom curve

Sunday, August 9th, 2009

Ever wanted to draw a curve directly through any number of points with the Flash Graphics class?

Here’s a class that will do that for you. It uses a “Catmull-Rom” spline (named after its inventors), which draws directly through any number of points.

It’s not a spectacular or pretty looking curve. It’s very “dowdy”, and somewhat ugly, but it doesn’t make wild swinging curves like many other equations. This humble quality makes it really good for situations where it’s important that the curve stays pretty close to the control points.

Example SWF (actionscript code)

CatmullRom curve actionscript class