| 1 |
package commands |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.utils.Timer; |
|---|
| 4 |
import flash.events.TimerEvent; |
|---|
| 5 |
|
|---|
| 6 |
/** |
|---|
| 7 |
* 「指定したミリ秒待機する」コマンド. |
|---|
| 8 |
* |
|---|
| 9 |
* <p>SerialCommandやParallelCommand等のバッチ処理系のコマンドにインターバルを挟む為に用います。</p> |
|---|
| 10 |
* |
|---|
| 11 |
* @example 以下はWaitCommandクラスの基本的な使い方です。この例では関数executeを実行して1秒後に、Event.COMPLETEが発行されます。 |
|---|
| 12 |
* <listing version="3.0"> |
|---|
| 13 |
* var command:ICommand = new WaitCommand(1000); |
|---|
| 14 |
* command.addEventListener(Event.COMPLETE, function():void{ |
|---|
| 15 |
* trace("Command Completed"); |
|---|
| 16 |
* }); |
|---|
| 17 |
* CommandContainer.execute( command );</listing> |
|---|
| 18 |
* |
|---|
| 19 |
* @example この例ではSerialCommandを用いて1秒待った後に文字列を表示しています。 |
|---|
| 20 |
* <listing version="3.0"> |
|---|
| 21 |
* var serial:SerialCommand = new SerialCommand(); |
|---|
| 22 |
* serial.push( new WaitCommand( 1000 )); |
|---|
| 23 |
* serial.push( new Command( null, trace, "Hello World" ); |
|---|
| 24 |
* |
|---|
| 25 |
* CommandContainer.execute( serial );</listing> |
|---|
| 26 |
* |
|---|
| 27 |
* @see commands.SerialCommand |
|---|
| 28 |
* @see commands.ParallelCommand |
|---|
| 29 |
* @see commands.CommandContainer |
|---|
| 30 |
*/ |
|---|
| 31 |
public class WaitCommand extends CommandBase |
|---|
| 32 |
{ |
|---|
| 33 |
protected var _timer:Timer |
|---|
| 34 |
protected var _delay:Number |
|---|
| 35 |
|
|---|
| 36 |
/** |
|---|
| 37 |
* 「指定したミリ秒だけ待つ」コマンド。 |
|---|
| 38 |
* |
|---|
| 39 |
* @param 待ち時間のミリ秒。 |
|---|
| 40 |
*/ |
|---|
| 41 |
public function WaitCommand( delay:Number = 1000) |
|---|
| 42 |
{ |
|---|
| 43 |
super(); |
|---|
| 44 |
_delay = delay |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
override public function execute():void |
|---|
| 49 |
{ |
|---|
| 50 |
_timer = new Timer(_delay, 1); |
|---|
| 51 |
_timer.addEventListener(TimerEvent.TIMER_COMPLETE, executeCompleteHandler); |
|---|
| 52 |
_timer.start(); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
protected function executeCompleteHandler(e:TimerEvent):void |
|---|
| 57 |
{ |
|---|
| 58 |
_timer.removeEventListener(TimerEvent.TIMER_COMPLETE, executeCompleteHandler ); |
|---|
| 59 |
_timer.stop(); |
|---|
| 60 |
_timer = null; |
|---|
| 61 |
dispatchComplete(); |
|---|
| 62 |
} |
|---|
| 63 |
} |
|---|
| 64 |
} |
|---|