diff --git a/src/as/com/threerings/flex/CommandButton.as b/src/as/com/threerings/flex/CommandButton.as index 1768cb45..1ecbb409 100644 --- a/src/as/com/threerings/flex/CommandButton.as +++ b/src/as/com/threerings/flex/CommandButton.as @@ -33,6 +33,32 @@ import com.threerings.util.CommandEvent; */ public class CommandButton extends Button { + /** + * A convenient factory method for creating CommandButtons. + * + * Usage: addChild(CommandButton.create("OK", function () :void { + * trace("ok clicked"); + * })); + */ + public static function create ( + label :String, cmdOrFn :* = null, arg :Object = null) :CommandButton + { + var cb :CommandButton = new CommandButton(); + cb.label = label; + if (cmdOrFn is Function) { + cb.setCallback(cmdOrFn as Function, arg) + + } else if (cmdOrFn is String) { + cb.setCommand(String(cmdOrFn), arg); + + } else if (cmdOrFn != null) { + // runtime errors suck, but this is actionscript + throw new Error("cmdOrFn must be a String or Function."); + } + + return cb; + } + /** * Create a command button. */