IfElseコマンドとForLoopコマンドを元に、WhileLoopコマンドを作ってみた。
■ソースはこちら
ForLoopをコピーして作ったので、内容的にはほとんど一緒。
どのくらい一緒かって言うと、ライセンス記述とかも全部一緒。
*
* Progression Framework
*
* @author Copyright (c) 2007 taka:nium.jp, supported by Spark project.
* @version 2.0.18
* @see http://progression.jp/
* @see http://progression.libspark.org/
*
* Project Manager
* taka:nium http://nium.jp/
*
* Hosted by
* Spark project http://www.libspark.org/
*
* Supported by
* yossy http://www.be-interactive.org/
* cellfusion http://cellfusion.jp/
* rch850 http://850mb.net/
* nobu http://humming.via-kitchen.com/
*
* Licensed under the MIT License
*
* Copyright (c) 2007 taka:nium.jp, supported by Spark project.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*//*=======================================================================*/
package org.tarotaro.flash.progression.commands {
import jp.progression.core.commands.Command;
import jp.progression.core.namespaces.progression_internal;
import jp.progression.events.CommandCatchEvent;
import jp.progression.events.CommandEvent;
/*======================================================================*//**
* WhileLoop クラスは指定された条件がtrueの間、コマンドを繰り返し実行するコマンドクラスです。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
* @example <listing version="3.0">
* import jp.progression.commands.WhileLoop;
* import jp.progression.commands.Trace;
*
* // WhileLoop コマンドを実行する
* new WhileLoop( 3, new Trace( "WhileLoop" ) )
* .before( null, trace, [ "ループ処理を実行します。" ] )
* .after( null, trace, [ "ループ処理を実行しました。" ] )
* .execute();
* </listing>
*//*=======================================================================*/
public class WhileLoop extends Command {
/*======================================================================*//**
* 条件の設定されている関数を取得または設定します。
* この関数は Boolean 型の戻り値が必要です。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
*//*=======================================================================*/
public function get condition() :Function { return _condition; }
public function set condition( value :Function ):void { _condition = value; }
private var _condition :Function;
/*======================================================================*//**
* 繰り返し実行したいコマンドを取得または設定します。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
*//*=======================================================================*/
public function get command() :Command { return _command; }
public function set command( value :Command ):void {
if ( _command ) {
// 関連性を削除する
_command.progression_internal::parent = null;
_command.progression_internal::depth = 0;
}
// 設定する
_command = value;
// 関連性を設定する
_command.progression_internal::parent = this;
_command.progression_internal::depth = progression_internal::depth + 1;
}
private var _command :Command;
/*======================================================================*//**
* 現在までに実行されたコマンドの合計回数を取得します。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
*//*=======================================================================*/
public function get currentCount() :int { return _currentCount; }
private var _currentCount :int = 0;
/*======================================================================*//**
* 新しい WhileLoop インスタンスを作成します。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
* @param condition 条件の設定されている関数です。この関数がtrueを返す間、コマンドを実行し続けます。
* @param command 繰り返し実行したいコマンドです。
* @param delay 処理開始まで遅延時間をミリ秒で指定します。
*//*=======================================================================*/
public function WhileLoop( condition:Function = null, command:Command = null, delay:int = 0 ) {
super( "WhileLoop", delay );
// 引数を設定する
this.condition = condition;
this.command = command;
}
/*======================================================================*//**
* @inheritDoc
* @langversion 3.0
* @playerversion Flash 9.0.45.0
*//*=======================================================================*/
protected override function _executeProgress():void {
// 処理を実行する
_execute();
}
/*======================================================================*//**
*
*//*=======================================================================*/
private function _execute():void {
var currentCondition:Boolean = _condition();
// 条件が false であれば終了する
if ( !currentCondition ) {
// 処理を終了する
_executeComplete();
return;
}
// 処理を実行する
_command.addExclusivelyEventListener( CommandEvent.COMMAND_COMPLETE, _commandComplete, false, int.MAX_VALUE, true );
_command.execute( extra );
}
/*======================================================================*//**
* @inheritDoc
* @langversion 3.0
* @playerversion Flash 9.0.45.0
*//*=======================================================================*/
protected override function _interruptProgress():void {
// イベントリスナーを解除する
_command.removeAllListeners( true );
// 停止する
_command.addExclusivelyEventListener( CommandEvent.COMMAND_INTERRUPT, _commandInterrupt, false, int.MAX_VALUE, true );
_command.interrupt( extra );
}
/*======================================================================*//**
* WhileLoop インスタンスのコピーを作成して、各プロパティの値を元のプロパティの値と一致するように設定します。
* @langversion 3.0
* @playerversion Flash 9.0.45.0
* @return 元のオブジェクトと同じプロパティ値を含む新しい WhileLoop インスタンスです。
*//*=======================================================================*/
public override function clone():Command {
var command:Command = new WhileLoop( _condition, _command ? _command.clone() : null, delay );
command.enabled = enabled;
command.before( _beforeScorp, _beforeFunc, _beforeArgs );
command.after( _afterScorp, _afterFunc, _afterArgs );
return command;
}
/*======================================================================*//**
* コマンドの処理が完了した場合に送出されます。
*//*=======================================================================*/
private function _commandComplete( e:CommandEvent ):void {
Command( e.target ).removeAllListeners( true );
// 処理を実行する
_execute();
}
/*======================================================================*//**
* コマンドの処理を停止した場合に送出されます。
*//*=======================================================================*/
private function _commandInterrupt( e:CommandEvent ):void {
Command( e.target ).removeAllListeners( true );
// 停止処理を終了する
_interruptComplete();
}
}
}
- ページ:
- 1
- 2




