Moved CommandEvent back, update imports.

git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@127 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Ray Greenwell
2007-01-31 03:03:17 +00:00
parent 76074998f4
commit 06f7f75fde
3 changed files with 4 additions and 88 deletions
@@ -4,6 +4,8 @@ import flash.events.MouseEvent;
import mx.controls.Button;
import com.threerings.util.CommandEvent;
/**
* A command button simply dispatches a Controller command (with an optional
* argument) when it is clicked.
@@ -1,88 +0,0 @@
package com.threerings.flex {
import flash.errors.IllegalOperationError;
import flash.events.Event;
import flash.events.IEventDispatcher;
public class CommandEvent extends Event
{
/** The event type for all controller events. */
public static const TYPE :String = "commandEvt";
/**
* Use this method to dispatch CommandEvents.
*/
public static function dispatch (
disp :IEventDispatcher, cmd :String, arg :Object = null) :void
{
// Create the event
var event :CommandEvent = create(cmd, arg);
// Dispatch it. A return value of true means that the event was
// never cancelled, so we complain.
if (disp == null || disp.dispatchEvent(event)) {
Log.getLog(CommandEvent).warning("Unhandled controller command " +
"[cmd=" + cmd + ", arg=" + arg + "].");
}
}
/** The command. */
public var command :String;
/** An optional argument. */
public var arg :Object;
/**
* Command events may not be directly constructed, use the dispatch
* method to do your work.
*/
public function CommandEvent (command :String, arg :Object)
{
super(TYPE, true, true);
if (_blockConstructor) {
throw new IllegalOperationError();
}
this.command = command;
this.arg = arg;
}
/**
* Mark this command as handled, stopping its propagation up the
* hierarchy.
*/
public function markAsHandled () :void
{
preventDefault();
stopImmediatePropagation();
}
override public function clone () :Event
{
return create(command, arg);
}
override public function toString () :String
{
return "CommandEvent[" + command + " (" + arg + ")]";
}
/**
* A factory method for privately creating command events.
*/
protected static function create (cmd :String, arg :Object) :CommandEvent
{
var event :CommandEvent;
_blockConstructor = false;
try {
event = new CommandEvent(cmd, arg);
} finally {
_blockConstructor = true;
}
return event;
}
/** Used to prevent unauthorized construction. */
protected static var _blockConstructor :Boolean = true;
}
}
@@ -10,6 +10,8 @@ import mx.core.mx_internal;
import mx.core.ScrollPolicy;
import mx.events.MenuEvent;
import com.threerings.util.CommandEvent;
/**
* A pretty standard menu that can submit CommandEvents if menu items
* have "command" and possibly "arg" properties. Commands are submitted to