In my recent collaboration with Kristofer Joseph, CandyPants, we needed a way to get the path to any function. At first, I tried describeType, which returns an XML object with all sorts of useful goodies about the provided object. Unfortunately, it’s not possible to send it the function you’re in without knowing it already. Luckily, I still have a hacky side that will consider the grossest code as a last resort. Here’s the result:
public static function getFunctionPath():String
{
return (new Error().getStackTrace().match(/at [^)]+\)/g)[1] as String).substr(3);
}
Sure, I could have spent tonight working on useful features for DestroyTwitter, but no, I wrote a KonamiCode. To use it, simply instantiate it with a stage and you’re good to go.
package com.destroytoday.desktop
{
import com.destroytoday.desktop.KonamiCode;
import flash.display.Sprite;
public class KonamiCodeTest extends Sprite
{
public var konamiCode:KonamiCode;
public function KonamiCodeTest()
{
konamiCode = new KonamiCode(stage);
konamiCode.executed.add(konamiCodeExecutedHandler);
}
protected function konamiCodeExecutedHandler():void
{
trace("woohoo!");
}
}
}
On a related note, I realized I’ve been neglecting GitHub for months, but now I’m back! I also plan to return to the experimentation game after reminiscing about my convex hull, delaunay triangulation, and voronoi studies at work today. When you develop apps all day, writing experiments can be a breath of fresh air, allowing a level of creativity you simply can’t get with apps.