Archive for the 'ActionScript' Category

Trimming in ActionScript jQuery-style

Sometimes we want to remove whitespace from the ends of our strings. In fact, this task is so common on the web that the ubiquitous jQuery library includes a utility method for that purpose.

What about in ActionScript 3? Well, not so much. The String class in AS3 is, in my opinion, a bit lacking compared to languages like C# and Scala. What’s worse, you can’t augment prototypes easily like you can in JavaScript to add missing methods (see update at the end for more information on this).

Read more »

SpriteFactory — an AS3 library for creating multiple sprites using the same bitmap

While working on Flash sidescroller stuff I noticed that there was no easy way (that I could find) to create multiple sprites from a single bitmap (something you’d do when doing a tile-based graphics layout).

Sooo… I made my own simple library called SpriteFactory.

Here’s some example usage:

var factory:SpriteFactory = new SpriteFactory("assets/sprites");
factory.loadBitmap("grass", "block-grass.png");
var grass1:Sprite = factory.newSprite("grass");
var grass2:Sprite = factory.newSprite("grass");

Check out the project page for more information.