Added a long-overdue factory method.
I'm actually going to make this the constructor, but I'm just fixing the build now. git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@407 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
@@ -33,6 +33,32 @@ import com.threerings.util.CommandEvent;
|
|||||||
*/
|
*/
|
||||||
public class CommandButton extends Button
|
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.
|
* Create a command button.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user