| 1 |
package commands |
|---|
| 2 |
{ |
|---|
| 3 |
import flash.events.Event; |
|---|
| 4 |
import flash.display.Stage; |
|---|
| 5 |
import flash.events.IEventDispatcher; |
|---|
| 6 |
|
|---|
| 7 |
/** |
|---|
| 8 |
* 「指定フレーム待つ」コマンド. |
|---|
| 9 |
* |
|---|
| 10 |
* <p>WaitCommandのonEnterFrame版です。指定フレーム数経過したらEvent.COMPLETEを発行します。</p> |
|---|
| 11 |
* |
|---|
| 12 |
* <p>WaitCommandの使用する為には初期化が必要です。初回クラス使用時の前にあらかじめ<code>WaitCommand.init</code>を呼び出してください。</p> |
|---|
| 13 |
* |
|---|
| 14 |
* @see commamds.WaitCommand |
|---|
| 15 |
*/ |
|---|
| 16 |
public class FrameWaitCommand extends CommandBase |
|---|
| 17 |
{ |
|---|
| 18 |
protected var count:int |
|---|
| 19 |
|
|---|
| 20 |
//onEnterFrameを受信する為に、enterFrameを発信できるクラスを渡す必要がある |
|---|
| 21 |
public static var enterFrameBeacon:IEventDispatcher |
|---|
| 22 |
|
|---|
| 23 |
public function FrameWaitCommand( count:int ) |
|---|
| 24 |
{ |
|---|
| 25 |
this.count = count; |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
/** |
|---|
| 29 |
* WaitCommandがEvent.ENTER_FRAMEを受け取れるように初期化します. |
|---|
| 30 |
* |
|---|
| 31 |
* 初回使用時の前に必ず呼び出してください。 |
|---|
| 32 |
* |
|---|
| 33 |
* @params stage ステージの参照 |
|---|
| 34 |
*/ |
|---|
| 35 |
public static function init( stage:Stage ):void |
|---|
| 36 |
{ |
|---|
| 37 |
enterFrameBeacon = stage; |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
override public function execute():void |
|---|
| 41 |
{ |
|---|
| 42 |
if(!enterFrameBeacon) |
|---|
| 43 |
throw new Error("FrameWaitCommand.init should be called before first execution."); |
|---|
| 44 |
enterFrameBeacon.addEventListener(Event.ENTER_FRAME, _enterFrameHandler, false, 0, true); |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
protected function _enterFrameHandler(e:Event):void |
|---|
| 49 |
{ |
|---|
| 50 |
if(count<=0){ |
|---|
| 51 |
IEventDispatcher(e.target).removeEventListener(e.type, arguments.callee); |
|---|
| 52 |
this.dispatchComplete(); |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
count--; |
|---|
| 56 |
} |
|---|
| 57 |
} |
|---|
| 58 |
} |
|---|