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:
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:
Demo (click to restart):
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.
Demo (click to restart):
4. Silly font glyph plotter
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:
That’s all, folks!