Permalink
Browse files

command

  • Loading branch information...
1 parent 14ede6c commit b5b4b0a9250318aaa8201020beb1cbad5177c917 @RhinoLu committed Feb 28, 2012
Showing with 64 additions and 0 deletions.
  1. +64 −0 lib/gtap/commands/Command.as
@@ -0,0 +1,64 @@
+package gtap.commands
+{
+ /**
+ * @author Allen Chou
+ */
+ import flash.events.Event;
+ import flash.events.EventDispatcher;
+ import flash.events.TimerEvent;
+ import flash.utils.Timer;
+ import org.osflash.signals.Signal;
+
+ public class Command extends EventDispatcher
+ {
+ private var _signal:Signal;
+ private var _timer:Timer;
+
+ public function Command(delay:Number = 0)
+ {
+ _timer = new Timer(int(1000 * delay), 1);
+ _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
+ _signal = new Signal();
+ }
+
+ private function onTimerComplete(e:TimerEvent):void
+ {
+ execute();
+ }
+
+ /**
+ * Starts the command.
+ * Waits for the timer to complete and calls the execute() method.
+ * This method can be used directly as an event listener.
+ */
+ public final function start(e:Event = null):void
+ {
+ _timer.start();
+ }
+
+ /**
+ * The abstract method for you to override to create your own command.
+ */
+ protected function execute():void
+ {
+
+ }
+
+ /**
+ * Completes the command.
+ * Dispatches a complete event.
+ * This method can be used directly as an event listener.
+ */
+ protected final function complete(type:String, obj:*= null):void
+ {
+ //dispatchEvent(new Event(Event.COMPLETE));
+ _signal.dispatch(type, obj);
+ _signal.removeAll();
+ }
+
+ public function get signal():Signal
+ {
+ return _signal;
+ }
+ }
+}

0 comments on commit b5b4b0a

Please sign in to comment.