| 1 |
package commands |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.events.Event; |
|---|
| 4 |
|
|---|
| 5 |
/** |
|---|
| 6 |
* 「全ての子コマンドを同時に実行し、その全ての終了を待つ」コマンド. |
|---|
| 7 |
* |
|---|
| 8 |
* <p>登録された複数のコマンドを全て同時に実行し、その全てのコマンドが終了するとEvent.COMPLETEが発行されます。 |
|---|
| 9 |
* 複数のデータが全てロードされるのを待つ時等に用いられます</p> |
|---|
| 10 |
* |
|---|
| 11 |
* @example 以下の例では、「文字の表示」「1秒待ち」「文字を表示」を同時に実行し、全てが終了した時点(つまり1秒後)にEvent.COMPLETEを発行します。" |
|---|
| 12 |
* <listing version="3.0"> |
|---|
| 13 |
* var coms : Array = [ |
|---|
| 14 |
* new Command("hello"), |
|---|
| 15 |
* new WaitCommand(1000), |
|---|
| 16 |
* new Command("world")]; |
|---|
| 17 |
* |
|---|
| 18 |
* var pCom : ParallelCommand = new ParallelCommand( coms ); |
|---|
| 19 |
* pCom.addEventListener(Event.COMPLETE, _commandCompleteHandler); |
|---|
| 20 |
* |
|---|
| 21 |
* CommandContainer.execute( pCom);</listing> |
|---|
| 22 |
* |
|---|
| 23 |
* @see commands.SerialCommand |
|---|
| 24 |
* @see commands.CommandContainer |
|---|
| 25 |
*/ |
|---|
| 26 |
public class ParallelCommand extends BatchCommand |
|---|
| 27 |
{ |
|---|
| 28 |
public function ParallelCommand( commandArray:Array = null ) |
|---|
| 29 |
{ |
|---|
| 30 |
super( commandArray ); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
override public function execute():void |
|---|
| 35 |
{ |
|---|
| 36 |
for(var i:int = 0; i<_commands.length; i++) |
|---|
| 37 |
{ |
|---|
| 38 |
var c : ICommand = _commands[ i ]; |
|---|
| 39 |
c.addEventListener(Event.COMPLETE, doNextCompleteHandler); |
|---|
| 40 |
c.execute(); |
|---|
| 41 |
} |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
protected function doNextCompleteHandler( e:Event ):void |
|---|
| 46 |
{ |
|---|
| 47 |
var c : ICommand = ICommand(e.target); |
|---|
| 48 |
c.removeEventListener(Event.COMPLETE, doNextCompleteHandler); |
|---|
| 49 |
_index ++; |
|---|
| 50 |
|
|---|
| 51 |
if(_index == _commands.length ) |
|---|
| 52 |
dispatchComplete(); |
|---|
| 53 |
} |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|