My Silly Gist Collection

I’ve been quite busy lately on both client and personal projects (can’t talk about the former, other than it being a big ass Flex 4 enterprise application i’ve been working on for the fine folks at Powerflasher; and it’s too early to talk about the latter.. stay tuned).

In the last few weeks i silently released random little experiments on Gist – mostly fallout from personal projects of mine. Nothing super impressive, all pretty rough, but i thought some of you might be interested.

So here it is, my silly Gist collection.

1. Show the compile date of a SWF

You are developing a Flex application. You frequently publish the application to a staging server for QA to test. You want to ensure that QA always tests the latest version of your application, because aggressive cache settings in browser or proxy servers may result in QA seeing outdated, cached SWFs.

To make sure that QA looks at the latest version of the SWF, you can have the SWF inspect itself and search for a ProductInfo tag, which contains the compile date (ProductInfo is an undocumented SWF tag, i explain it in more detail here). You can then have your Flex application display this date in order to be able to verify that QA sees the latest version.

Here’s how to do that:

http://gist.github.com/594367

2. Bin Packer

For a project i am working on, i needed an algorithm to fit as many randomly sized rectangles as possible into a given, larger rectangle (the bin). Turned out, there are a lot of different approaches out there (unfortunately none of the more elaborate ones is much better than O(argh) – the more rectangles you try to fit, the slower the algorithms get).

I found one resource particularly helpful: clb.demon.fi explains some selected Bin Packer algorithms in great detail, and provides many links to others. They also provide a C implementation for a bunch of algorithms.

I ported their Max Rect Bin Packer implementation to ActionScript 3, and added the option to have it execute asynchronously:

http://gist.github.com/543176

Demo (click to restart):

This movie requires Flash Player 10

3. De Casteljau: Move a point along a quadratic bezier

Recently i needed an algorithm to split a quadratic bezier curve in two. The solution was De Casteljau’s algorithm.

http://gist.github.com/524163

Demo (click to restart):

This movie requires Flash Player 10

4. Silly font glyph plotter

This Flash movie parses itself, grabs the first glyph of an embedded font and draws it on screen (uses as3swf to parse itself, so you need as3swf.swc). Kinda silly.

http://gist.github.com/523033

Demo:

This movie requires Flash Player 10

5. Convert HTML to XML and use E4X to access DOM (AIR required)

Here’s a little utility function i wrote. XMLUtils.jsDomToE4X() converts HTML loaded via HTMLLoader (or the HTML DOM to be exact) into an AS3 XML object, so you can use simple E4X queries to scrape a HTML page. Evil.

And here’s the source code for a minimalistic web browser built upon the Adobe AIR Flex HTML component, that dumps out the URLs of SWFs embedded into the loaded HTML document.

The basic idea:

var x:XML = XMLUtil.jsDomToE4X(htmlControl.domWindow.document);
var ns:Namespace = Namespace("http://www.w3.org/1999/xhtml");
var embeds:XMLList = x..ns::embed.@src;

The full source:

http://gist.github.com/456130

That’s all, folks!

I hope you enjoyed my silly little collection. Please also check out my “serious” work on GitHub, and feel free to follow me on Twitter.

2 thoughts on “My Silly Gist Collection

  1. Hi ,

    thanks for the very good posts!
    I was trying to Transform Shapes With the Mouse on run-time with Flash, if possible in AS2 , But Not Got any Good Luck for that, As You are a Master of that, I hope you help me to make it !

    Thanks
    deepak

Comments are closed.