Skip to content

Instantly share code, notes, and snippets.

View destroytoday's full-sized avatar

Jonnie Hallman destroytoday

View GitHub Profile
// This is a super ghetto way of getting the path to a function
// It will only work in Flash Player Debugger and ADL
// ex: com.destroytoday.pool::ObjectWaterpark/getObjectPool()
// updated: Jackson Dunstan pointed out the code works without throwing the error
public static function getFunctionPath():String
{
return (new Error().getStackTrace().match(/at [^)]+\)/g)[1] as String).substr(3);
}
@destroytoday
destroytoday / gist:737905
Created December 12, 2010 07:26
Static constructor
package com.destroytoday.example
{
public class StaticClass
{
{ trace('constructed'); } // <-- static constructor
}
}
var hotkeyManager:HotkeyManager = new HotkeyManager(stage);
// use-case with handlers
hotkeyManager.createHotkey("@").executed.add(lookupUserHotkeyHandler);
hotkeyManager.createHotkey("command+s").executed.add(saveHotkeyHandler);
// use-case with commands
signalCommandMap.mapSignal(hotkeyManager.createHotkey("@").executed, lookupUserCommand);
signalCommandMap.mapSignal(hotkeyManager.createHotkey("command+s").executed, saveCommand);
@destroytoday
destroytoday / gist:747732
Created December 19, 2010 21:58
Instantiating a Stage for unit testing
stage = new NativeWindow(new NativeWindowInitOptions()).stage;
@destroytoday
destroytoday / MenuItem.as
Created December 21, 2010 02:55
How AIR's menu classes should look
package com.destroytoday.view.component.menu
{
import flash.display.NativeMenuItem;
public class MenuItem extends NativeMenuItem
{
public function MenuItem(label:String, keyEquivalentModifiers:Array = null, keyEquivalent:String = null)
{
super(label, false);
@destroytoday
destroytoday / gist:749498
Created December 21, 2010 04:43
One-liner for creating and setting a NativeMenuItem with a menu
// can be used to create a menubar without a ton of boilerplate
(fileItem = new NativeMenuItem("File")).submenu = new NativeMenu();
@destroytoday
destroytoday / gist:749666
Created December 21, 2010 08:36
How to unfocus a NativeWindow for unit testing
// At the moment, AIR only has activate() and bringToFront() for focusing windows,
// but it lacks any methods for unfocusing. Though unfocusing a window is a pretty
// rare action, it's necessary for some unit tests. Mine test a minimize menu item
// that is expected to be disabled if no windows are focused. I don't see the AIR
// team adding a deactivate() method, but I do see the possibility of setting
// NativeApplication.nativeApplication.activeWindow to null. Right now, it's read-only.
var window:NativeWindow = NativeApplication.nativeApplication.activeWindow;
window.visible = false;
@destroytoday
destroytoday / FileMenu.as
Created December 26, 2010 19:01
Making AIR menus usable
package com.destroytoday.example
{
import com.destroytoday.menu.IMenuGroup;
import com.destroytoday.menu.MenuGroup;
import com.destroytoday.menu.SeparatedMenu;
import flash.ui.Keyboard;
public class FileMenu extends SeparatedMenu
{
@destroytoday
destroytoday / gist:755581
Created December 26, 2010 19:22
The problems with AIR menus
NativeMenuItem(label:String = '', isSeparator:Boolean = false);
protected var shape:Shape = new Shape();
public function invalidate():void
{
shape.addEventListener(Event.ENTERFRAME, invalidateHandler);
}
protected function invalidateHandler(event:Event):void
{
stage.removeEventListener(Event.ENTERFRAME, invalidateHandler);